home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / shell / SKsh017.lzh / scr_source / popd.s < prev    next >
Encoding:
Text File  |  1991-04-26  |  1008 b   |  31 lines

  1. #!c:sksh
  2.  
  3. #*************************************************************************
  4. # This function implements the popd operation.  It accepts no arguments,
  5. # and simply pops a directory off the stack and returns to that point.
  6. # it complains if the directory stack is empty.
  7. #*************************************************************************
  8.  
  9.    local _new_dir
  10.  
  11.    if [ "$#" -ne '0' -o "$1" = '-?' ]
  12.    then
  13.       echo 'Usage:' $(basename $0)
  14.       echo '       (pops directory from directory stack)'
  15.       return 1
  16.    fi
  17.  
  18.    # --- if the DIRSTACK is empty, print that fact and exit ------------------
  19.  
  20.    [ -z "$DIRSTACK" ] && echo 'The directory stack is empty' && return 1
  21.  
  22.    # --- extract the new directory and remove it from the DIRSTACK -----------
  23.  
  24.    _new_dir   = $(car "$DIRSTACK" ',')
  25.    DIRSTACK  = $(cdr "$DIRSTACK" ',')
  26.    export -l DIRSTACK
  27.  
  28.    # --- cd to the new place and complain if we can't ------------------------
  29.  
  30.    cd "$_new_dir" >nil: || echo "$0: Can't cd to $_new_dir."
  31.