popd

来自「Berkely的学生写的」· 代码 · 共 59 行

TXT
59
字号
#!/bin/sh# Chapter 14 - Functions# This script implements the csh command popd, it removes the directory# at the top of the directory stack and changes into that directory.# This implementation consists of two functions, a helper function called# _popd_helper and popd. The helper function is not ment to be called # directly by users.# To use this function you need to "source" it into your environment using# the . command_popd_helper() {    # set the directory to pop to the first argument, if     # this directory is empty, issue an error and return 1    # otherwise get rid of POPD from the arguments    POPD="$1"    if [ -z "$POPD" ] ; then        echo "ERROR: The directory stack is empty." >&2        return 1    fi    shift    # if any more arguments remain, reinitalize the directory    # stack, and then update it with the remaining items,     # otherwise set the directory stack to null    if [ -n "$1" ] ; then         _DIR_STACK="$1" ;         shift ;        for i in $@ ; do _DIR_STACK="$_DIR_STACK:$i" ; done    else        _DIR_STACK=    fi    # if POPD is a directory cd to it, otherwise issue    # an error message    if [ -d "$POPD" ] ; then        cd "$POPD" > /dev/null 2>&1        if [ $? -ne 0 ] ; then            echo "ERROR: Could not cd to $POPD." >&2        fi        pwd    else        echo "ERROR: $POPD is not a directory." >&2    fi    export _DIR_STACK    unset POPD}popd() {    OLDIFS="$IFS"    IFS=:    _popd_helper $_DIR_STACK    IFS="$OLDIFS"}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?