LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General > LinuxQuestions.org Member Intro
User Name
Password
LinuxQuestions.org Member Intro New to LinuxQuestions.org? Been a long time member but never made a post? Introduce yourself here.

Notices

Reply
 
Search this Thread
Old 04-30-2009, 04:25 AM   #1
vipinchauhan
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: 0
cd command doesn't work in script with more than two arguments in quotes


hi .
the cd command is not working in shell script with more than two arguments (directory name with two string).
but is working on command prompt with same arguments in quotes..........
whether the shell is not able to parse the arguments because of spaces in the strings........???

Last edited by vipinchauhan; 04-30-2009 at 11:13 PM.
 
Old 04-30-2009, 02:39 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,973
Blog Entries: 5

Rep: Reputation: 778Reputation: 778Reputation: 778Reputation: 778Reputation: 778Reputation: 778Reputation: 778
I don't understand what you're asking. "cd" is "change directory" and takes exactly one argument which is the directory to which you wish to change.

If you put two items in quotes with a space between them then it means your directory has a space in its name. In that case it is still ONE argument not two.

Quotes from command line are taken by the shell you're already in but those from a script are taken by a sub shell. Also it would depend on the line you're running because other commands might require extra quoting or escaping.

You might try simply putting quotes around your quotes:
cd ""one two""
Or single quotes:
cd '"one two"'
Or escaping the quotes:
cd \"one two\"

It truly depends on exactly what you're attempting to do.
 
Old 04-30-2009, 11:26 PM   #3
vipinchauhan
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Its not working .........
Even if at command prompt i assign a variable to the dual directory string and pass it to cd ....its not working
y='Backup vipin '
cd $y
 
Old 04-30-2009, 11:57 PM   #4
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
cd "$y"
 
Old 05-01-2009, 11:12 PM   #5
vipinchauhan
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
cd "$y" doesn't work

Quote:
Originally Posted by billymayday View Post
cd "$y"
Sir,
If we do the following even on the command prompt ....even that doesn't work...
y="'/Volumes/Backup vipin/'"
echo $y
'/Volumes/Backup vipin/'
cd "$y"



the following error was encountered........
-sh: cd: '/Volumes/Backup vipin/': No such file or directory.
But the direct arguments are given to cd at the command prompt
cd '/Volumes/Backup vipin/'
vipinchauhans-power-mac-g4:/Volumes/Backup vipin root#

..that works.....
why its not working with a variable ........
 
Old 05-01-2009, 11:20 PM   #6
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Don' put the single quotes in there

y="/Volumes/Backup vipin/"

not

y="'/Volumes/Backup vipin/'"
 
  


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
shell script: how to insert a command into quotes alekone Linux - General 4 01-12-2009 08:56 AM
Shell Script format question - output command results in quotes Barefootpanda Linux - General 5 10-13-2008 11:40 PM
How can I pipe output of a command into arguments of a script HGeneAnthony Linux - General 3 12-26-2007 06:24 AM
same find command not working in bash script, quotes? QuakerOatz Linux - Software 1 07-14-2003 12:04 PM
Quotes in command line expression afshin Programming 4 02-24-2003 07:27 AM


All times are GMT -5. The time now is 11:25 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration