Linux Newbie help
 help / color / mirror / Atom feed
* Variable Quoting
@ 2002-10-14 16:02 Paul Kraus
  2002-10-14 16:32 ` Jim Reimer
  2002-10-14 20:54 ` Don Petrowski
  0 siblings, 2 replies; 13+ messages in thread
From: Paul Kraus @ 2002-10-14 16:02 UTC (permalink / raw)
  To: linux-newbie

I am having trouble quoting with variables. 

For example

source="/backup/My\ Documents/*"
cp ${source} /tmp

When I run this it will see everything up to my and bomb.
Now if I type the exact same path in the exact same way into the code

cp /backup/My\ Documents/*"
It will work fine.

This is not a real world example. I made this up for this email. I am
having this kind of problems with many commands.
Another better example would be...

subj="This is a test email"
mutt -s ${subj} someemailaddress < somemessage

When this is run This becomes the subject and the rest of $subj became
email address. I have also tried escaping the spaces with \ and it does
not work. But when entered directly into the command it works fine.


Paul Kraus
Network Administrator
PEL Supply Company
216.267.5775 Voice
216-267-6176 Fax
www.pelsupply.com

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-14 16:02 Variable Quoting Paul Kraus
@ 2002-10-14 16:32 ` Jim Reimer
  2002-10-14 16:38   ` Jim Reimer
  2002-10-14 20:54 ` Don Petrowski
  1 sibling, 1 reply; 13+ messages in thread
From: Jim Reimer @ 2002-10-14 16:32 UTC (permalink / raw)
  To: Paul Kraus; +Cc: linux-newbie

Paul Kraus wrote:
> I am having trouble quoting with variables. 
> 
> For example
> 
> source="/backup/My\ Documents/*"
> cp ${source} /tmp

either protect with quotes -or- escape the space...

source="/backup/My Documents/*"     (quotes, no escape)
or
source=/backup/My\ Documents/*      (escape, no quotes)

don't do both.

> 
> When I run this it will see everything up to my and bomb.
> Now if I type the exact same path in the exact same way into the code
> 
> cp /backup/My\ Documents/*"
> It will work fine.
> 
> This is not a real world example. I made this up for this email. I am
> having this kind of problems with many commands.
> Another better example would be...
> 
> subj="This is a test email"
> mutt -s ${subj} someemailaddress < somemessage

protect the variable with quotes:

mutt -s "$subj" someemail.......

( by the way....

you don't have to surround the variable name with braces unless it's
right up against something else, as in

filename="test"
cp somefile ${test}.txt

if it's seperated by white space they don't have to be there

)

> 
> When this is run This becomes the subject and the rest of $subj became
> email address. I have also tried escaping the spaces with \ and it does
> not work. But when entered directly into the command it works fine.
> 
> 
> Paul Kraus
> Network Administrator
> PEL Supply Company
> 216.267.5775 Voice
> 216-267-6176 Fax
> www.pelsupply.com

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-14 16:32 ` Jim Reimer
@ 2002-10-14 16:38   ` Jim Reimer
  2002-10-14 17:59     ` Paul Kraus
  0 siblings, 1 reply; 13+ messages in thread
From: Jim Reimer @ 2002-10-14 16:38 UTC (permalink / raw)
  Cc: Paul Kraus, linux-newbie

> ( by the way....
> 
> you don't have to surround the variable name with braces unless it's
> right up against something else, as in
> 
> filename="test"
> cp somefile ${test}.txt
> 
> if it's seperated by white space they don't have to be there
> 
> )

oops - my face is red now.....

that should have been

filename="test"
cp somefile $(filename).txt


sorry
-jdr-


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Variable Quoting
  2002-10-14 16:38   ` Jim Reimer
@ 2002-10-14 17:59     ` Paul Kraus
  0 siblings, 0 replies; 13+ messages in thread
From: Paul Kraus @ 2002-10-14 17:59 UTC (permalink / raw)
  To: 'Jim Reimer', linux-newbie

Ok I found out how to prevent it for separating the words as different
arguments. I need to encapsulate the variable with quotes.

How ever I am needing to do this with the cp command. When I try double
quoting a path with spaces in it for cp I get an error. If I make the
string somevariable="somediretory/somesubdirectory/some\ directory\
with\ spaces/*"
Then when substition takes place 
cp $somevarable $somedestination
Then it should read
cp /somedirectory/somesubdirectory/some\ directory\ with\ spaces/* /tmp
This is correct syntax for cp and if I type it out or use file name
completion that is the format the shell uses. However when done this way
I also get an error.

It appears that substition is taking place but it is handling the escape
sequence wrong.



-----Original Message-----
From: linux-newbie-owner@vger.kernel.org
[mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of Jim Reimer
Sent: Monday, October 14, 2002 12:39 PM
To: unlisted-recipients:; no To-header on input
Cc: Paul Kraus; linux-newbie@vger.kernel.org
Subject: Re: Variable Quoting


> ( by the way....
> 
> you don't have to surround the variable name with braces unless it's 
> right up against something else, as in
> 
> filename="test"
> cp somefile ${test}.txt
> 
> if it's seperated by white space they don't have to be there
> 
> )

oops - my face is red now.....

that should have been

filename="test"
cp somefile $(filename).txt


sorry
-jdr-


-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in the body of a message to majordomo@vger.kernel.org More majordomo
info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Variable Quoting
       [not found] <200210142055.11942.linux-newbie@jimmo.com>
@ 2002-10-14 18:38 ` Paul Kraus
  2002-10-14 19:58   ` James Mohr
  0 siblings, 1 reply; 13+ messages in thread
From: Paul Kraus @ 2002-10-14 18:38 UTC (permalink / raw)
  To: linux-newbie, linux-newbie

That is what I did.

---Directory is real and does exist and path verified using file
completion.
Here is an example.
string="/My Documents"
ls "$string"

Does work as it is intended.

Now with this change
string="My Documents/*"
cp "$string" /tmp

cp: cannot stat 'My Documents/*':no such file or directory
So then I for kicks I tried.

cp "My Documents/*" /tmp
Produces the same error.

So just to make sure that it was not a typo in path I tried.
cp My\ Documents/* /tmp

And this worked.

So is the problem with cp? Since the same syntax seems to work with all
other apps?
Is cp not capable of taking a double quoted path with spaces?

Redhat 7.3 in case it helps. 


-----Original Message-----
From: James Mohr [mailto:linux-newbie@jimmo.com] 
Sent: Monday, October 14, 2002 2:55 PM
To: Paul Kraus
Subject: Re: Variable Quoting


On Monday 14 October 2002 19:59, Paul Kraus wrote:
> Ok I found out how to prevent it for separating the words as different

> arguments. I need to encapsulate the variable with quotes.
>
> How ever I am needing to do this with the cp command. When I try 
> double quoting a path with spaces in it for cp I get an error. If I 
> make the string somevariable="somediretory/somesubdirectory/some\ 
> directory\ with\ spaces/*" Then when substition takes place
> cp $somevarable $somedestination
> Then it should read
> cp /somedirectory/somesubdirectory/some\ directory\ with\ spaces/*
/tmp
> This is correct syntax for cp and if I type it out or use file name
> completion that is the format the shell uses. However when done this
way
> I also get an error.
>
> It appears that substition is taking place but it is handling the 
> escape sequence wrong.

Hi Paul!
If you assign a value to a variable using quotes, then the value is
assigned 
** without** the quotes. This is because the shell gets ahold of it a
reduces 
each command to "tokens" and one of the tokens is the text **inside**
the 
quotes. Also the expansion takes place by the shell before it is passed
on to 
the copy command. 

Look at these examples:
mdkir 'My Documents'
DIR='My Documents'
ls $DIR
ls: My: No such file or directory
ls: Documents: No such file or directory

Makes sense as the variable $DIR contains the literal text, including
the 
space. The command that is execute is:

ls My Documents

and neither of these exists. If you try:

ls -ld "$DIR"
drwxr-xr-x    2 root     root           48 Oct 14 20:44 My Documents

This works because the $DIR is expanded by the shell and it plus the
quotes 
become the "token" which is then passed to the the ls command. 

Your examples will work as long as you ensure that the variables are
include 
inside of quotes, for example, this works:

cp "$somevarable" "$somedestination"

Regards,

jimmo

-- 
---------------------------------------
"Be more concerned with your character than with your reputation. Your
character is what you really are while your reputation is merely what
others think you are." -- John Wooden
---------------------------------------
Be sure to visit the Linux Tutorial:  http://www.linux-tutorial.info
---------------------------------------
NOTE: All messages sent to me in response to my posts to newsgroups or
forums 
are subject to reposting.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Variable Quoting
  2002-10-14 19:58   ` James Mohr
@ 2002-10-14 19:53     ` Paul Kraus
  2002-10-15 16:13       ` Paul Furness
  2002-10-14 19:55     ` Paul Kraus
  1 sibling, 1 reply; 13+ messages in thread
From: Paul Kraus @ 2002-10-14 19:53 UTC (permalink / raw)
  To: linux-newbie, linux-newbie

Ok I lied. I understand why its not working but how should I workaround
it?
Do I have to have my script gather a list of the files and the pass it
the variable?
That sucks that I can not use a wildcard to just get all.

I have made these changes. Which I though would fix my problem.
string="My Documents/"
cp "${string}*" Which I thought would eliminate the problem. I guess I
am not understanding.


-----Original Message-----
From: linux-newbie-owner@vger.kernel.org
[mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of James Mohr
Sent: Monday, October 14, 2002 3:58 PM
To: linux-newbie@vger.kernel.org
Subject: Re: Variable Quoting



On Monday 14 October 2002 20:38, Paul Kraus wrote:
<SNIP>
> Now with this change
> string="My Documents/*"
> cp "$string" /tmp
>
> cp: cannot stat 'My Documents/*':no such file or directory

Sure because the token that is passed to the cp command includes the
asterisk, 
it doesn't know that it should expand the asterisk (*) to the file
names, so 
it looks for a file with the literal name '*'. 

> So then I for kicks I tried.
>
> cp "My Documents/*" /tmp
> Produces the same error.

Same thing.

>
> So just to make sure that it was not a typo in path I tried. cp My\ 
> Documents/* /tmp
>
> And this worked.

Makes sense as the shell is now expanding the asterisks to the names of
the 
files. You don't see this because it is expanded internally. Create a
shell 
script that just does this copy and put "set -x" on the first list. This

should show you the expanded form before it is passed to cp.

> So is the problem with cp? Since the same syntax seems to work with 
> all other apps? Is cp not capable of taking a double quoted path with 
> spaces?

No, it is the fact that cp does not know to expand the asterisk. Plus
you are 
passing different things to the cp depending on what sets of quotes you
use.

> Redhat 7.3 in case it helps.
Actually the Linux distriubtion is pretty irrelevant in this case. In
fact the 
behavior would be the same on most any *NIX system, as it is standard
shell 
stuff. 

See if these explain more of the details for you:

http://www.linux-tutorial.info/cgi-bin/display.pl?20&0&0&0&3
http://www.linux-tutorial.info/cgi-bin/display.pl?22&0&0&0&3

regards,

jimmo

-- 
---------------------------------------
"Be more concerned with your character than with your reputation. Your
character is what you really are while your reputation is merely what
others think you are." -- John Wooden
---------------------------------------
Be sure to visit the Linux Tutorial:  http://www.linux-tutorial.info
---------------------------------------
NOTE: All messages sent to me in response to my posts to newsgroups or
forums 
are subject to reposting.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in the body of a message to majordomo@vger.kernel.org More majordomo
info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Variable Quoting
  2002-10-14 19:58   ` James Mohr
  2002-10-14 19:53     ` Paul Kraus
@ 2002-10-14 19:55     ` Paul Kraus
  2002-10-14 21:00       ` James Mohr
  1 sibling, 1 reply; 13+ messages in thread
From: Paul Kraus @ 2002-10-14 19:55 UTC (permalink / raw)
  To: linux-newbie, linux-newbie

GOT IT!!!

Cp "$variable"* 

Thanks again!

-----Original Message-----
From: linux-newbie-owner@vger.kernel.org
[mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of James Mohr
Sent: Monday, October 14, 2002 3:58 PM
To: linux-newbie@vger.kernel.org
Subject: Re: Variable Quoting



On Monday 14 October 2002 20:38, Paul Kraus wrote:
<SNIP>
> Now with this change
> string="My Documents/*"
> cp "$string" /tmp
>
> cp: cannot stat 'My Documents/*':no such file or directory

Sure because the token that is passed to the cp command includes the
asterisk, 
it doesn't know that it should expand the asterisk (*) to the file
names, so 
it looks for a file with the literal name '*'. 

> So then I for kicks I tried.
>
> cp "My Documents/*" /tmp
> Produces the same error.

Same thing.

>
> So just to make sure that it was not a typo in path I tried. cp My\ 
> Documents/* /tmp
>
> And this worked.

Makes sense as the shell is now expanding the asterisks to the names of
the 
files. You don't see this because it is expanded internally. Create a
shell 
script that just does this copy and put "set -x" on the first list. This

should show you the expanded form before it is passed to cp.

> So is the problem with cp? Since the same syntax seems to work with 
> all other apps? Is cp not capable of taking a double quoted path with 
> spaces?

No, it is the fact that cp does not know to expand the asterisk. Plus
you are 
passing different things to the cp depending on what sets of quotes you
use.

> Redhat 7.3 in case it helps.
Actually the Linux distriubtion is pretty irrelevant in this case. In
fact the 
behavior would be the same on most any *NIX system, as it is standard
shell 
stuff. 

See if these explain more of the details for you:

http://www.linux-tutorial.info/cgi-bin/display.pl?20&0&0&0&3
http://www.linux-tutorial.info/cgi-bin/display.pl?22&0&0&0&3

regards,

jimmo

-- 
---------------------------------------
"Be more concerned with your character than with your reputation. Your
character is what you really are while your reputation is merely what
others think you are." -- John Wooden
---------------------------------------
Be sure to visit the Linux Tutorial:  http://www.linux-tutorial.info
---------------------------------------
NOTE: All messages sent to me in response to my posts to newsgroups or
forums 
are subject to reposting.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in the body of a message to majordomo@vger.kernel.org More majordomo
info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-14 18:38 ` Paul Kraus
@ 2002-10-14 19:58   ` James Mohr
  2002-10-14 19:53     ` Paul Kraus
  2002-10-14 19:55     ` Paul Kraus
  0 siblings, 2 replies; 13+ messages in thread
From: James Mohr @ 2002-10-14 19:58 UTC (permalink / raw)
  To: linux-newbie


On Monday 14 October 2002 20:38, Paul Kraus wrote:
<SNIP>
> Now with this change
> string="My Documents/*"
> cp "$string" /tmp
>
> cp: cannot stat 'My Documents/*':no such file or directory

Sure because the token that is passed to the cp command includes the asterisk, 
it doesn't know that it should expand the asterisk (*) to the file names, so 
it looks for a file with the literal name '*'. 

> So then I for kicks I tried.
>
> cp "My Documents/*" /tmp
> Produces the same error.

Same thing.

>
> So just to make sure that it was not a typo in path I tried.
> cp My\ Documents/* /tmp
>
> And this worked.

Makes sense as the shell is now expanding the asterisks to the names of the 
files. You don't see this because it is expanded internally. Create a shell 
script that just does this copy and put "set -x" on the first list. This 
should show you the expanded form before it is passed to cp.

> So is the problem with cp? Since the same syntax seems to work with all
> other apps?
> Is cp not capable of taking a double quoted path with spaces?

No, it is the fact that cp does not know to expand the asterisk. Plus you are 
passing different things to the cp depending on what sets of quotes you use.

> Redhat 7.3 in case it helps.
Actually the Linux distriubtion is pretty irrelevant in this case. In fact the 
behavior would be the same on most any *NIX system, as it is standard shell 
stuff. 

See if these explain more of the details for you:

http://www.linux-tutorial.info/cgi-bin/display.pl?20&0&0&0&3
http://www.linux-tutorial.info/cgi-bin/display.pl?22&0&0&0&3

regards,

jimmo

-- 
---------------------------------------
"Be more concerned with your character than with your reputation. Your
character is what you really are while your reputation is merely what others
think you are." -- John Wooden
---------------------------------------
Be sure to visit the Linux Tutorial:  http://www.linux-tutorial.info
---------------------------------------
NOTE: All messages sent to me in response to my posts to newsgroups or forums 
are subject to reposting.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-14 16:02 Variable Quoting Paul Kraus
  2002-10-14 16:32 ` Jim Reimer
@ 2002-10-14 20:54 ` Don Petrowski
  1 sibling, 0 replies; 13+ messages in thread
From: Don Petrowski @ 2002-10-14 20:54 UTC (permalink / raw)
  To: Paul Kraus; +Cc: linux-newbie

Give this a try

> string somevariable="somediretory/somesubdirectory/some\ directory\
   with\ spaces/*"

string somevariable="somediretory/somesubdirectory/some directory with
spaces/*"

> cp $somevarable $somedestination

cp "$somevarable" $somedestination



-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-14 19:55     ` Paul Kraus
@ 2002-10-14 21:00       ` James Mohr
  0 siblings, 0 replies; 13+ messages in thread
From: James Mohr @ 2002-10-14 21:00 UTC (permalink / raw)
  To: linux-newbie

On Monday 14 October 2002 21:55, Paul Kraus wrote:
> GOT IT!!!
>
> Cp "$variable"*

Sort of. That obviously works. Since the asterisks and the variable are 
expanded seperately in this case, it works. However, it may not work in every 
case depending on what you are trying to accomplished. If you want to copy 
everything, including all sub-directories, you can forget the asterisk and 
simply use the -R option to cp.

Regards,

jimmo

>
> Thanks again!
>
> -----Original Message-----
> From: linux-newbie-owner@vger.kernel.org
> [mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of James Mohr
> Sent: Monday, October 14, 2002 3:58 PM
> To: linux-newbie@vger.kernel.org
> Subject: Re: Variable Quoting
>
>
>
> On Monday 14 October 2002 20:38, Paul Kraus wrote:
> <SNIP>
>
> > Now with this change
> > string="My Documents/*"
> > cp "$string" /tmp
> >
> > cp: cannot stat 'My Documents/*':no such file or directory
>
> Sure because the token that is passed to the cp command includes the
> asterisk,
> it doesn't know that it should expand the asterisk (*) to the file
> names, so
> it looks for a file with the literal name '*'.
>
> > So then I for kicks I tried.
> >
> > cp "My Documents/*" /tmp
> > Produces the same error.
>
> Same thing.
>
> > So just to make sure that it was not a typo in path I tried. cp My\
> > Documents/* /tmp
> >
> > And this worked.
>
> Makes sense as the shell is now expanding the asterisks to the names of
> the
> files. You don't see this because it is expanded internally. Create a
> shell
> script that just does this copy and put "set -x" on the first list. This
>
> should show you the expanded form before it is passed to cp.
>
> > So is the problem with cp? Since the same syntax seems to work with
> > all other apps? Is cp not capable of taking a double quoted path with
> > spaces?
>
> No, it is the fact that cp does not know to expand the asterisk. Plus
> you are
> passing different things to the cp depending on what sets of quotes you
> use.
>
> > Redhat 7.3 in case it helps.
>
> Actually the Linux distriubtion is pretty irrelevant in this case. In
> fact the
> behavior would be the same on most any *NIX system, as it is standard
> shell
> stuff.
>
> See if these explain more of the details for you:
>
> http://www.linux-tutorial.info/cgi-bin/display.pl?20&0&0&0&3
> http://www.linux-tutorial.info/cgi-bin/display.pl?22&0&0&0&3
>
> regards,
>
> jimmo

-- 
---------------------------------------
"Be more concerned with your character than with your reputation. Your
character is what you really are while your reputation is merely what others
think you are." -- John Wooden
---------------------------------------
Be sure to visit the Linux Tutorial:  http://www.linux-tutorial.info
---------------------------------------
NOTE: All messages sent to me in response to my posts to newsgroups or forums 
are subject to reposting.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Variable Quoting
  2002-10-14 19:53     ` Paul Kraus
@ 2002-10-15 16:13       ` Paul Furness
  2002-10-16  7:23         ` ichi
  0 siblings, 1 reply; 13+ messages in thread
From: Paul Furness @ 2002-10-15 16:13 UTC (permalink / raw)
  To: Paul Kraus; +Cc: linux-newbie, linux-newbie

There are a couple of approaches.

One way is to enclose the entire path in quotes then stick the asterisk
on the end - as in:

cp "My Documents/"* /tmp

which you can then use a variable for like this:

Path="My Documents"
cp "${Path}"/* /tmp

You could also use a for loop:

Path="My Documents/"

for FILENAME in ls "${Path}"
do
	cp "${Path}${Filename}" "/tmp"
done

Note that this second way of doing it will create "/tmp/My Documents"...
but the first way will put the files in /tmp

P.



On Mon, 2002-10-14 at 20:53, Paul Kraus wrote:
> Ok I lied. I understand why its not working but how should I workaround
> it?
> Do I have to have my script gather a list of the files and the pass it
> the variable?
> That sucks that I can not use a wildcard to just get all.
> 
> I have made these changes. Which I though would fix my problem.
> string="My Documents/"
> cp "${string}*" Which I thought would eliminate the problem. I guess I
> am not understanding.
> 
> 
> -----Original Message-----
> From: linux-newbie-owner@vger.kernel.org
> [mailto:linux-newbie-owner@vger.kernel.org] On Behalf Of James Mohr
> Sent: Monday, October 14, 2002 3:58 PM
> To: linux-newbie@vger.kernel.org
> Subject: Re: Variable Quoting
> 
> 
> 
> On Monday 14 October 2002 20:38, Paul Kraus wrote:
> <SNIP>
> > Now with this change
> > string="My Documents/*"
> > cp "$string" /tmp
> >
> > cp: cannot stat 'My Documents/*':no such file or directory
> 
> Sure because the token that is passed to the cp command includes the
> asterisk, 
> it doesn't know that it should expand the asterisk (*) to the file
> names, so 
> it looks for a file with the literal name '*'. 
> 
> > So then I for kicks I tried.
> >
> > cp "My Documents/*" /tmp
> > Produces the same error.
> 
> Same thing.
> 
> >
> > So just to make sure that it was not a typo in path I tried. cp My\ 
> > Documents/* /tmp
> >
> > And this worked.
> 
> Makes sense as the shell is now expanding the asterisks to the names of
> the 
> files. You don't see this because it is expanded internally. Create a
> shell 
> script that just does this copy and put "set -x" on the first list. This
> 
> should show you the expanded form before it is passed to cp.
> 
> > So is the problem with cp? Since the same syntax seems to work with 
> > all other apps? Is cp not capable of taking a double quoted path with 
> > spaces?
> 
> No, it is the fact that cp does not know to expand the asterisk. Plus
> you are 
> passing different things to the cp depending on what sets of quotes you
> use.
> 
> > Redhat 7.3 in case it helps.
> Actually the Linux distriubtion is pretty irrelevant in this case. In
> fact the 
> behavior would be the same on most any *NIX system, as it is standard
> shell 
> stuff. 
> 
> See if these explain more of the details for you:
> 
> http://www.linux-tutorial.info/cgi-bin/display.pl?20&0&0&0&3
> http://www.linux-tutorial.info/cgi-bin/display.pl?22&0&0&0&3
> 
> regards,
> 
> jimmo
> 
> -- 
> ---------------------------------------
> "Be more concerned with your character than with your reputation. Your
> character is what you really are while your reputation is merely what
> others think you are." -- John Wooden
> ---------------------------------------
> Be sure to visit the Linux Tutorial:  http://www.linux-tutorial.info
> ---------------------------------------
> NOTE: All messages sent to me in response to my posts to newsgroups or
> forums 
> are subject to reposting.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie"
> in the body of a message to majordomo@vger.kernel.org More majordomo
> info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
> 
-- 
Paul Furness

Systems Manager

2+2=5 for extremely large values of 2.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-15 16:13       ` Paul Furness
@ 2002-10-16  7:23         ` ichi
  2002-10-16 10:51           ` Paul Furness
  0 siblings, 1 reply; 13+ messages in thread
From: ichi @ 2002-10-16  7:23 UTC (permalink / raw)
  To: Paul Furness; +Cc: Paul Kraus, linux-newbie, linux-newbie

Paul Furness wrote:
> 
> Path="My Documents/"
> for FILENAME in ls "${Path}"
> do
>      cp "${Path}${Filename}" "/tmp"
> done

I think you mean:
----------------------------------
Path="My Documents/"
for FILENAME in `ls "${Path}"`
do
    cp "${Path}${FILENAME}" "/tmp"
done
----------------------------------
Note the changes in lines two and four.


Cheers,
Steven

______________________________
http://www.volny.cz/basiclinux

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Variable Quoting
  2002-10-16  7:23         ` ichi
@ 2002-10-16 10:51           ` Paul Furness
  0 siblings, 0 replies; 13+ messages in thread
From: Paul Furness @ 2002-10-16 10:51 UTC (permalink / raw)
  To: ichi; +Cc: linux-newbie, linux-newbie

Oops. <looks sheepish> I did indeed mean for both instances of the word
"Filename" to be in the same case.
<sigh> I must be getting old; either that or I'm not drinking enough
coke.

Apologies if I caused any confusion. :)

P.

On Wed, 2002-10-16 at 08:23, ichi@ihug.co.nz wrote:
> Paul Furness wrote:
> > 
> > Path="My Documents/"
> > for FILENAME in ls "${Path}"
> > do
> >      cp "${Path}${Filename}" "/tmp"
> > done
> 
> I think you mean:
> ----------------------------------
> Path="My Documents/"
> for FILENAME in `ls "${Path}"`
> do
>     cp "${Path}${FILENAME}" "/tmp"
> done
> ----------------------------------
> Note the changes in lines two and four.
> 
> 
> Cheers,
> Steven
> 
> ______________________________
> http://www.volny.cz/basiclinux
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
> 
-- 
Paul Furness

Systems Manager

2+2=5 for extremely large values of 2.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2002-10-16 10:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-14 16:02 Variable Quoting Paul Kraus
2002-10-14 16:32 ` Jim Reimer
2002-10-14 16:38   ` Jim Reimer
2002-10-14 17:59     ` Paul Kraus
2002-10-14 20:54 ` Don Petrowski
     [not found] <200210142055.11942.linux-newbie@jimmo.com>
2002-10-14 18:38 ` Paul Kraus
2002-10-14 19:58   ` James Mohr
2002-10-14 19:53     ` Paul Kraus
2002-10-15 16:13       ` Paul Furness
2002-10-16  7:23         ` ichi
2002-10-16 10:51           ` Paul Furness
2002-10-14 19:55     ` Paul Kraus
2002-10-14 21:00       ` James Mohr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox