#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    76
    Rep Power
    15

    $OLDPWD is empty


    Hello all.

    I am currently trying to write a script using the Korn shell.

    The idea is that the user types back into the terminal and they are taken to their previous working directory, however, it appears that the $OLDPWD environmental variable is empty.

    Any help that can be provided would be appreciated. Also any alternative methods of achieving this would be appreciated.

    Regards, Matt.
  2. #2
  3. No Profile Picture
    ......@.........
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2004
    Posts
    1,345
    Rep Power
    59
    Code:
    cd -
    returns to the previous working directory. ksh does not depend on OLDPWD, because cd is internal command.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    76
    Rep Power
    15
    Originally Posted by jim mcnamara
    Code:
    cd -
    returns to the previous working directory. ksh does not depend on OLDPWD, because cd is internal command.
    This returns "back[3]: cd: bad directory".

    I load up in /home/matt/ and 'cd' to 'documents' then type back but this is what I get.

    Thank you for your quick reply!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    210
    Rep Power
    31
    Not sure what you're doing to get that error, but my guess is that you've put the previous command into a shell script? Try setting up an alias like so:

    Code:
    $ alias back="cd -"
    $ pwd
    /home/ded
    $ cd working
    $ pwd
    /home/ded/working
    $ back
    /home/ded
    $ pwd
    /home/ded
    $
    Though, I'm not sure how much time you are really saving by setting up an alias that is just as many characters as the original command?

IMN logo majestic logo threadwatch logo seochat tools logo