Results 1 to 10 of 10
Hi there,
I would like to create a script, for example "xyz" that will change my current working directory to a specific location in my Linux file system.
I tried ...
- 12-19-2006 #1Just Joined!
- Join Date
- Dec 2006
- Posts
- 6
Scripts to change the working directory
Hi there,
I would like to create a script, for example "xyz" that will change my current working directory to a specific location in my Linux file system.
I tried this with adding "cd /home/WMD/XYZFolder" to a script file called xyx, it would not work.
I put xyz in the /user/local/bin folder and set its permisions to (user=)rwx. I know that the script executed, because I added an echo statement which was displayed when I ran it. However, it never left me in the said folder.
What's the trick?
Thanks,
WMD
- 12-19-2006 #2Just Joined!
- Join Date
- Feb 2003
- Posts
- 6
When you execute a script (i.e. /path/to/script) it runs in runs in a separate shell and then exits to your original shell. In your case the directory change happens in the shell the script is running in. So to get it to run in the current shell, you have to source it.
Create your script with the cd command.
Then run it like this:
I would create your script and then add an alias to your .bashrc file like this:Code:$ source /path/to/script
Then you should be able to type xyz at the command line and get what you want.Code:alias xyz='source /path/to/script'
- 12-19-2006 #3Just Joined!
- Join Date
- Dec 2006
- Posts
- 6
Thanks for the tip. I'll give it a shot.
- 12-19-2006 #4
Aliases would work well for that purpose as well (e.g. http://bliki.rimuhosting.com/space/k...g+with+aliases)
- 12-19-2006 #5Just Joined!
- Join Date
- Feb 2003
- Posts
- 6
hugghitt1 is right.
You could real easily create an alias to do this. If all you have in your script is to change directory, no point in scripting that.
Just create an alias in .bashrc
- 12-20-2006 #6Just Joined!
- Join Date
- Dec 2006
- Posts
- 6
I've been looking around for .bashrc for a while. Yesterday I found it in /usr/local/bin. I added the previously mentioned file "xyz" to the same folder and inserted an alias='source /usr/bin/local/xyz' line to .bashrc. I also played around with chmod on some test folders and I had to use it to make xyz work properly. Here's the result: This morning, nothing was accessible. I got libc??? input/output errors, couldn't run any programs and got stuck shutting Linux down. I powered off and on, and my boot failed.
Originally Posted by Netizen
Any ideas? Can a bit of tweaking in the Linux system do this?
I am using UBUNTU 6.0 something LTS. I think I'll try to boot the UBUNTU CD again and see what it can do.
Hmm, not a good start to today.
- 12-20-2006 #7Just Joined!
- Join Date
- Feb 2003
- Posts
- 6
Yes..depending on what you change.
Originally Posted by WMD
First off, whats in your script? are you just doing a change directory?
I would do the following alias in your bashrc (located at /home/you/.bashrc):
alias xyz='cd /path/to/directory'
Then you could just type $ xyz and change directories. No scripts, no changing permissions on folders.
Second, if you have more than cd in the script and are the only one using the script, just leave it in your home directory. I have a lot of scripts I have written, and I just put them in:
/home/me/bin
root can still use them with the path, and you can always add the path to your profile.
Here is a sample .bashrc file:
http://tldp.org/LDP/abs/html/sample-bashrc.html
- 12-20-2006 #8Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
If you are going to the "specific location" often, there is a feature in many shells, including bash, that may serve your purpose. It is CDPATH. It seems relatively unknown, but I have used it upon occasion when I have a project directory buried deep and I want to quickly go there frequently.
There is an easy-to-read article at http://www.macosxhints.com/article.p...05031814311425 , but not very much beyond a mention in man bash.
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 12-21-2006 #9Just Joined!
- Join Date
- Dec 2006
- Posts
- 6
I am just changing directories. Later I may add some setup. Eventually I want more than 100 abc shortcuts being installed, for each of the main xyz shortcuts. For now, this sounds much simpler than I expected. Thanks for the tips and the link.
Originally Posted by Netizen
- 12-21-2006 #10Just Joined!
- Join Date
- Dec 2006
- Posts
- 6
Thanks for the suggestion and the link.
Originally Posted by drl


Reply With Quote