![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| changing multiple directory names w/ sed | RahJiggah | OS X (Apple) | 1 | 11-05-2007 09:55 AM |
| Changing Directory Using SFU | ilak1008 | Windows & DOS: Issues & Discussions | 1 | 05-21-2007 11:50 PM |
| /root directory - date keeps changing??? | Alux | Linux | 1 | 03-16-2006 02:28 AM |
| changing directory on server | bb00y | High Level Programming | 1 | 12-05-2003 08:59 PM |
| Changing directory on Unix | taher_n | UNIX for Advanced & Expert Users | 3 | 06-04-2002 09:45 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Changing directory through script
Hi Friends !
I want to change my current directory through a script. I am running the script say, from /home/proj directory. The script is like this : #!/usr/bin/sh cd module/pack/data once i run the script, i am still in /home/proj directory only. My problem is, i dont want to type the big directory structure every time i want to change the directory. So, say i will place the above 2 lines in a file named "a" and i will just i run "a" , i will be taken into /home/proj/module/pack/data directory directly. please suggest me a way out for this ! thanks, |
| Forum Sponsor | ||
|
|
|
||||
|
As Phantom indicates, the easiest way would be to define an alias or function within your shells initialisation files that do this.
Have a look at my sample .kshrc file. There is a "cd aliases" section there.... Obviously this is for the Korn shell but most of it will work with bash too. As pressy indicates, setting up environment variables with commonly navigated directories is also a good idea. Define and export them within your .profile (or .bash_profile, whatever), e.g. export WEB=/path/to/my/webroot Then, to edit a file, for example, all you have to type is vi $WEB/index.html Cheers ZB |
|
|||
|
Meaning of . ./myscript.ksh
Thanks for your reply.
But I would like to know what does it mean to shell by typing . ./myscript.ksh rather than ./myscript.ksh Can you please explain me. Thanks, Quote:
|
|
|||
|
Quote:
In contrast, by running as ./myscript, the script will be executed in subshell and directory (or variable) changes done in it will be effective only until the script exits. |
|||
| Google The UNIX and Linux Forums |