LinuxQuestions.org
Visit Jeremy's Blog.
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 03-12-2010, 01:37 AM   #1
Kilam orez
Member
 
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33

Rep: Reputation: 15
Red face 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
 
Old 03-12-2010, 01:44 AM   #2
Galib
Member
 
Registered: Mar 2009
Location: $HOME
Distribution: Slackware64
Posts: 69

Rep: Reputation: 17
EDIT: Mis-Read your question.

Last edited by Galib; 03-12-2010 at 01:46 AM.
 
Old 03-12-2010, 01:52 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
Old 03-12-2010, 03:42 AM   #4
Kilam orez
Member
 
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33

Original Poster
Rep: Reputation: 15
Red face

Quote:
Originally Posted by evo2 View Post
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
 
Old 03-12-2010, 03:48 AM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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

Code:
. fc_mov_2.sh
Cheers,

Evo2.

Last edited by evo2; 03-12-2010 at 03:50 AM.
 
Old 03-12-2010, 03:58 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by evo2 View Post
First, remove the "#!/bin/bash" from the first line
Wouldn't do any harm but not necessary.
 
Old 03-12-2010, 04:30 AM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by catkin View Post
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.
 
Old 03-12-2010, 05:14 AM   #8
Kilam orez
Member
 
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by evo2 View Post
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

Code:
. fc_mov_2.sh
Cheers,

Evo2.
Thank you Evo2, it worked !!!!
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
1st script attempt; cygwin; fails "bash: myscript : command not found" engineerd1 Linux - Newbie 8 11-08-2009 05:03 PM
bash script: how to check stderr after command "find" Vilmerok Programming 1 07-08-2009 08:35 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 02:45 AM


All times are GMT -5. The time now is 05:15 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