LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2004, 04:52 AM   #1
pit1516
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Rep: Reputation: 0
shell scripts & change dir


hi all,

i've tried to write a small shell script which changes the current directory to one i frequently need to go to. it looks something like this:

cd /SCR/fmri-exp/nc_vass/mri

that's all. funny thing is, it doesn't work. it DOES work if i type it that way on the command prompt, but not when it's written in a script. why ?!?

- pit
 
Old 06-22-2004, 05:41 AM   #2
zoran
LQ Newbie
 
Registered: Sep 2003
Location: Belgrade
Distribution: SUSE 9.0
Posts: 6

Rep: Reputation: 0
You should put

#!/bin/sh

at the beginning of the script
 
Old 06-22-2004, 08:47 AM   #3
pit1516
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
doesn't work
 
Old 06-22-2004, 08:53 AM   #4
arobic
Member
 
Registered: Jul 2003
Location: Geneva, Switzerland
Distribution: Debian 3.1, SLC3 (based on RHEL)
Posts: 84

Rep: Reputation: 15
Hi pit!

From what I know, if you change dir in a shell script, it will change it only during the execution of the script. Whenever the script stops, you go back to the directory where the schell script was executed.

So if you want to cd to somewhere and execute commands there, you should:
Code:
#!/bin/sh
#
cd /SCR/fmri-exp/nc_vass/mri
 commands-to-be-done
#
exit 0
Hope this helps!
 
Old 06-22-2004, 09:04 AM   #5
pit1516
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
ah !

thanks man so that's my problem. is there any way to PERMANENTLY change the current directory from within a shell script ? anything else won't be particularly usefull for my purposes, since there's a number of different (and changing) things to be done from there.

- pit
 
Old 06-22-2004, 10:32 AM   #6
miss crump
LQ Newbie
 
Registered: May 2004
Location: Oklahoma City, OK
Distribution: Debian
Posts: 17

Rep: Reputation: 0
If all you want to do is change the directory, you could just create an alias, something like:

alias cdmri='cd /SCR/fmri-exp/nc_vass/mri'

Put that in your .bashrc file, source it and all you have to do is type in cdmri and you'll be where you want to be.
 
Old 06-22-2004, 11:42 AM   #7
pit1516
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
thanks, that's actually working just like i wanted it to and it's also going to save me loads of time, since that's not the only cryptic path i frequently need to change to. thanks again !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adduser but no shell and no home dir ryedunn Linux - Newbie 7 09-05-2011 10:52 AM
shell script + change shell && continue darkRoom Programming 6 02-25-2005 03:50 AM
Bash Scripts for Dir listing jchristman Linux - General 6 08-26-2004 09:58 AM
change dir alaios Linux - General 5 03-15-2004 06:41 AM
Change kde theme & wallpaper from command line or start scripts? JHuizingh Linux - Software 2 12-11-2003 07:44 PM


All times are GMT -5. The time now is 08:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration