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 |
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.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
9354.1 | can't do that | TUXEDO::CHUBB | Wed Apr 02 1997 11:06 | 26 | |
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.2 | If you need a shell in a new directory ... | QUARRY::reeves | Jon Reeves, UNIX compiler group | Wed Apr 02 1997 19:03 | 8 |
...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. |