* Positional parameters with more than one space
@ 2004-01-29 22:50 David Gómez
2004-01-30 0:23 ` Bob Schmertz
0 siblings, 1 reply; 3+ messages in thread
From: David Gómez @ 2004-01-29 22:50 UTC (permalink / raw)
To: Zsh-users
Hi all ;),
I'm coding a shell function that receives several files as parameters. These
files usually will have spaces in its names, so i want this function to
work correctly with spaces.
I'm using the $@ array to iterate thru all parameters, with a for loop:
for i in "$@"; do
something
done
And it works fine, except when a file has more that one space in its name.
I mean, if one of the files is "more than one space", after the $@
expansion it transforms to "more that one space" which obviously doesn't
exists. How can i avoid this?
Thanks a lot,
--
David Gómez
"The question of whether computers can think is just like the question of
whether submarines can swim." -- Edsger W. Dijkstra
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Positional parameters with more than one space
2004-01-29 22:50 Positional parameters with more than one space David Gómez
@ 2004-01-30 0:23 ` Bob Schmertz
2004-02-02 8:52 ` David Gómez
0 siblings, 1 reply; 3+ messages in thread
From: Bob Schmertz @ 2004-01-30 0:23 UTC (permalink / raw)
To: David Gómez, Zsh-users
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1412 bytes --]
--- David Gómez <david@pleyades.net> wrote:
> Hi all ;),
>
> I'm coding a shell function that receives several files as parameters.
> These
> files usually will have spaces in its names, so i want this function to
> work correctly with spaces.
>
> I'm using the $@ array to iterate thru all parameters, with a for loop:
>
> for i in "$@"; do
> something
> done
>
> And it works fine, except when a file has more that one space in its
> name.
> I mean, if one of the files is "more than one space", after the $@
> expansion it transforms to "more that one space" which obviously
> doesn't
> exists. How can i avoid this?
>
You haven't given us enough info about where the parameters are coming
from (i.e., how you're calling your script) or what you're doing with
them inside the loop.
Here is a complete sample script called check_spaces.zsh:
#!/bin/zsh
for file in "$@"
do
/bin/echo $file
/bin/echo "$file"
done
# --end--
If I call it thus:
check_spaces.zsh *
I get two spaces for a file that has two consecutive spaces in its name.
If I run it with bash, however, I get consolidated spaces in the output
of the first echo line, without the parameter quoted.
In short, I don't know why you're having problems :-)
=====
Cheers,
Bob Schmertz
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Positional parameters with more than one space
2004-01-30 0:23 ` Bob Schmertz
@ 2004-02-02 8:52 ` David Gómez
0 siblings, 0 replies; 3+ messages in thread
From: David Gómez @ 2004-02-02 8:52 UTC (permalink / raw)
To: robert.schmertz; +Cc: Zsh-users
Hi Bob ;),
> You haven't given us enough info about where the parameters are coming
> from (i.e., how you're calling your script) or what you're doing with
> them inside the loop.
I'm calling the script using shell globbing to select the set of files. But
you solved my problem with your sample script ;). The problem was that
i wasn't quoting the variable, and thus the spaces were 'compressed'. I
was using the expression: 'command $FILES' when i should be using 'command
"$FILES"'. I didn't know about that zsh behavior with spaces.
Thanks a lot for you help ;)
--
David Gómez
"The question of whether computers can think is just like the question of
whether submarines can swim." -- Edsger W. Dijkstra
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-02-02 8:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-29 22:50 Positional parameters with more than one space David Gómez
2004-01-30 0:23 ` Bob Schmertz
2004-02-02 8:52 ` David Gómez
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).