Escaping "a multiword arugment" into sh

Escaping "a multiword arugment" into sh

Post by Marty Leisner 257 » Wed, 14 Sep 1994 00:58:06



How do I write shell loops such that
foo "this is one arg" "this is another arg"

will come up right when I do:

for i in $*
do
        echo $i
done

(I want to see
"this is one arg"
"this is another arg"

instead of
this
is
one
arg
this
is
another
arg

--
marty

Member of the League for Programming Freedom
We don't actually do anything new in computing, we just rename the old stuff.
                                Grace Murray Hopper, who OOed in 1944

 
 
 

Escaping "a multiword arugment" into sh

Post by Michael Salm » Wed, 14 Sep 1994 19:09:24




|>
|> How do I write shell loops such that
|> foo "this is one arg" "this is another arg"
|>
|> will come up right when I do:


|>
|> for i in $*
|> do
|>   echo $i
|> done

--

Michael Salmon

#include        <standard.disclaimer>
#include        <witty.saying>
#include        <fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm

 
 
 

Escaping "a multiword arugment" into sh

Post by Chet Ram » Wed, 14 Sep 1994 23:03:20




Quote:

>How do I write shell loops such that
>foo "this is one arg" "this is another arg"

>will come up right when I do:

>for i in $*


--
``The lyf so short, the craft so long to lerne.'' - Chaucer


 
 
 

Escaping "a multiword arugment" into sh

Post by Gary Gobel HI » Sat, 17 Sep 1994 18:14:57



>How do I write shell loops such that
>foo "this is one arg" "this is another arg"
>will come up right when I do:
>for i in $*
>do
>    echo $i
>done
>(I want to see
>"this is one arg"
>"this is another arg"
>instead of
>this
>is
>one
>arg
>this
>is
>another
>arg
>--
>marty

>Member of the League for Programming Freedom
>We don't actually do anything new in computing, we just rename the old stuff.
>                                Grace Murray Hopper, who OOed in 1944

Try:

#!/bin/ksh
IFS="
"

for i in $*
do
        echo $i
done

====================================================================
Gary G. Gobel                          



====================================================================

 
 
 

Escaping "a multiword arugment" into sh

Post by Chris Bitme » Sun, 25 Sep 1994 01:14:32




>>How do I write shell loops such that
>>foo "this is one arg" "this is another arg"

>>will come up right when I do:

>>for i in $*
>>do
>>        echo $i
>>done

>>(I want to see
>>"this is one arg"
>>"this is another arg"

>>instead of
>>this
>>is
>>one
>>arg
>>this
>>is
>>another
>>arg

>>--
>>marty

>>Member of the League for Programming Freedom
>>We don't actually do anything new in computing, we just rename the old stuff.
>>                                Grace Murray Hopper, who OOed in 1944

>Try:

>#!/bin/ksh
>IFS="
>"

>for i in $*
>do
>        echo $i
>done

NO!

like this:


do
        echo "$i"
done

or even better:

for i
do
        echo "$i"
done

 
 
 

1. dowhat=`expr "dowhat.sh" : "\(.*\)\.sh$"`;

This is from a Bash shell script.  The purpose is to get at the base
name of the script (which is contained within the script variable $0),
using the regular expression mode of expr.

.* matches 0 to infinity (the *) chars (the .) except for a newline,
and the escaped parentheses are needed to encapsulate that expression
for some reason. \.sh$ specifies ".sh" occurring at the end of a line
(escape needed to specify a literal .).

Please explain how this strips off the .sh extension.  If you enter
dowhat.sh in Emacs, and search using this regular expression, it
happily matches the whole shebang, whereas as used in the script, the
extension is subtracted!

Good regular expressions tutorial:
http://www-105.ibm.com/developerworks/education.nsf/linux-onlinecours...

2. Q&A from this NG 14 May

3. more secure?: "#!/bin/sh -" or "#!/bin/sh"

4. Patch: linux-2.5.42/kernel/sys.c - warm reboot should not suspend device

5. Is "sh file" equivalent to "cat file | sh"

6. Compiling for DOS with gcc

7. GETSERVBYNAME()????????????????????"""""""""""""

8. HPSB #13 - Revised Edition

9. sh says: test "$1" = "" when $1="-b"

10. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

11. csh: escaping "{" and "}" in command substitution

12. Need to disable "!"(escape to shell) while in "more"

13. Type "(", ")" and "{", "}" in X...