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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-12-2010, 01:37 AM
|
#1
|
Member
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33
Rep:
|
command " cd .. " not working in bash script?
Hi dear linux users.
i wonder why the cd ./.. or cd ./../ or
cd .. command does not work, when used in bash script.
But it works fine, when used on the command line.
can i anybody tell me, why is it so? sorry if my question is silly.
With Regards,
kilam
|
|
|
03-12-2010, 01:44 AM
|
#2
|
Member
Registered: Mar 2009
Location: $HOME
Distribution: Slackware64
Posts: 69
Rep:
|
EDIT: Mis-Read your question.
Last edited by Galib; 03-12-2010 at 01:46 AM.
|
|
|
03-12-2010, 01:52 AM
|
#3
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
What do you mean "does not work?". What happens? Is there an error?
Can you make the script output pwd before and after tring to cd?
Cheers,
Evo2.
|
|
|
03-12-2010, 03:42 AM
|
#4
|
Member
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33
Original Poster
Rep:
|
Quote:
Originally Posted by evo2
What do you mean "does not work?". What happens? Is there an error?
Can you make the script output pwd before and after tring to cd?
Cheers,
Evo2.
|
hi,
my script(fc_mov_2.sh) is:----
#!/bin/bash
cd ./../
#----end---------
when i run it, i get:---
hg@hg:~/Desktop/is64/trial> ./fc_mov_2.sh
hg@hg:~/Desktop/is64/trial> pwd
/home/hg/Desktop/is64/trial
No error is shown. i wonder, what is happening?
regards,
kilam
Last edited by Kilam orez; 03-12-2010 at 03:44 AM.
Reason: extra
|
|
|
03-12-2010, 03:48 AM
|
#5
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
The script is a separate process. To illustrate (as I suggeted in my first post), use the following script:
Code:
#!/bin/bash
pwd
cd ..
pwd
The script can't change the working dir of the shell that calls it. If you really want to do something like that you need to source the script. First, remove the "#!/bin/bash" from the first line and then do
Cheers,
Evo2.
Last edited by evo2; 03-12-2010 at 03:50 AM.
|
|
|
03-12-2010, 03:58 AM
|
#6
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by evo2
First, remove the "#!/bin/bash" from the first line
|
Wouldn't do any harm but not necessary.
|
|
|
03-12-2010, 04:30 AM
|
#7
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Quote:
Originally Posted by catkin
Wouldn't do any harm but not necessary.
|
Good point. I guess it's just a convention I use so that when I look at a script I immediately know whether it should be sourced or executed.
Cheers,
Evo2.
|
|
|
03-12-2010, 05:14 AM
|
#8
|
Member
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33
Original Poster
Rep:
|
Quote:
Originally Posted by evo2
The script is a separate process. To illustrate (as I suggeted in my first post), use the following script:
Code:
#!/bin/bash
pwd
cd ..
pwd
The script can't change the working dir of the shell that calls it. If you really want to do something like that you need to source the script. First, remove the "#!/bin/bash" from the first line and then do
Cheers,
Evo2.
|
Thank you Evo2, it worked !!!!
|
|
|
All times are GMT -5. The time now is 08:35 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|