[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9354.0. "Change directory and shell program" by DEKVC::JUNMOKSONG () Wed Apr 02 1997 03:49

    Hi,
    
    
    How are you?
    I want to know how to change default directory by shell program
    as following:
    
    -----Sample shell---------
    
    #!/bin/csh
    cd /usr
    ls
    ----------------------------
    
    After I execute above shell at /, the directory also is / .
    so how can I change directory from / to /usr after running shell
    
    program?
    Best Regards,
    Jun-Mok song
    
T.RTitleUserPersonal
Name
DateLines
9354.1can't do thatTUXEDO::CHUBBWed Apr 02 1997 11:0626
    When you execute a shell script, a new shell is spawned to do it.  When
    it exits, you're back in your original environment, which includes the
    original directory. Now if you were to 'source' the script instead of
    running it, then the changes will be permanent. If its something you
    need all the time, then make an alias.  So the script could be called
    foo:
    
    ----
    #!/bin/csh
    cd /usr ; ls
    ---
    
    Then in your .cshrc file, make an alias:
    alias lsusr 'source ~/bin/foo'
    
    Then at your command prompt you can just type 'lsusr' to automatically
    go to /usr and do a listing (and remain at /usr after the listing).
    
    Or more simply, you could just have the alias be:
    alias lsusr 'cd /usr ; ls'
    
    ..but that assumes your script is really that simple.  The more
    complicated your script, the more you'll actually want it to be a
    standalone script.
    
    -- brandon
9354.2If you need a shell in a new directory ...QUARRY::reevesJon Reeves, UNIX compiler groupWed Apr 02 1997 19:038
...then start one up in the script.

#!/bin/csh
cd /
csh

This is a quick and dirty kludge, since it gives you a couple of extra shell
processes.