Problem printing "*" and "?" in sh. HELP!

Problem printing "*" and "?" in sh. HELP!

Post by guess who... » Thu, 15 Dec 1994 05:02:55



Hi... I have a question in shell script, so i will be appreciated if
anyone can solve my problem. Here is the code:

pattern=" dd  *  ddd ?"
set $pattern
for word
do
        echo $word
done

The question is, instead of printing "dd", "*", "dd" and "?",
the shell treats * and ? as wildcard chars. That is, it prints
all my filenames instead of a regular "*" and "?" string. So
is there any way to fix this? I am limited to using sh only, and
no PERL... etc.

Kenny

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Andreas Schw » Thu, 15 Dec 1994 23:09:07



|> Hi... I have a question in shell script, so i will be appreciated if
|> anyone can solve my problem. Here is the code:

|> pattern=" dd  *  ddd ?"
|> set $pattern
|> for word
|> do
|>   echo $word
|> done

Add `set -f' to disable file name generation (globbing).
--
Andreas Schwab                                      "And now for something


 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Praveen C. Pu » Fri, 16 Dec 1994 04:20:54



|>
|> Hi... I have a question in shell script, so i will be appreciated if
|> anyone can solve my problem. Here is the code:
|>
|> pattern=" dd  *  ddd ?"
|> set $pattern
|> for word
|> do
|>   echo $word
|> done
|>
|> The question is, instead of printing "dd", "*", "dd" and "?",
|> the shell treats * and ? as wildcard chars. That is, it prints
|> all my filenames instead of a regular "*" and "?" string. So
|> is there any way to fix this? I am limited to using sh only, and
|> no PERL... etc.
|>
|> Kenny

Add:
    set -f $pattern

as the first line of the script.  This will set file generation off.

So, the whole script is:

set -f $pattern
pattern=" dd  *  ddd ?"
set $pattern
for word
do
        echo $word
done

--
Praveen Puri
Domestic Project Group
Motorola
"Have sh, will travel"

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Hrvoje Niks » Fri, 16 Dec 1994 07:20:55



[... 12 lines deleted ...]

Quote:> Add `set -f' to disable file name generation (globbing).

$ set -f
-f: bad option(s)
$

Hrv
--
Hrvoje Niksic             |  Student of electrical engineering

--------------------------------------------------------------
- "What is it that a man may call the greatest things in life?"
- "Hot water, good dentishtry and shoft lavatory paper."
        -- Cohen the Barbarian in conversation with Discworld nomads
           (Terry Pratchett, The Light Fantastic)

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Magnus Nasho » Fri, 16 Dec 1994 23:26:41



Quote:>Hi... I have a question in shell script, so i will be appreciated if
>anyone can solve my problem. Here is the code:
>pattern=" dd  *  ddd ?"
>set $pattern
>for word
>do
>    echo $word
>done
>The question is, instead of printing "dd", "*", "dd" and "?",
>the shell treats * and ? as wildcard chars. That is, it prints
>all my filenames instead of a regular "*" and "?" string. So
>is there any way to fix this? I am limited to using sh only, and
>no PERL... etc.

This work for sh:
set -f
pattern=" dd * ddd ?"

echo $pattern
for shit in $pattern
do
    echo $shit
done

Somethings in your script didn't make sense, but with the command 'set -f' you
disable filename-generation.
You can also use this line as the first line of the script:
#!/bin/sh -f
and skip the 'set' command.
/Magnus

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Chet Ram » Sun, 18 Dec 1994 00:45:29



>|>> Add `set -f' to disable file name generation (globbing).

>|> $ set -f
>|> -f: bad option(s)
>|> $

>Sorry, looks like this is SunOS sh and bash specific.

It's not that bad.  The -f option to set was added to sh in
system III.  Only the Ultrix sh and the old BSD (v7) sh do not
have it.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer


 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Andreas Schw » Sat, 17 Dec 1994 23:03:59



|> [... 12 lines deleted ...]
|>> Add `set -f' to disable file name generation (globbing).

|> $ set -f
|> -f: bad option(s)
|> $

Sorry, looks like this is SunOS sh and bash specific.
--
Andreas Schwab                                      "And now for something

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Hrvoje Niks » Mon, 19 Dec 1994 22:54:19



Quote:> >|> $ set -f
> >|> -f: bad option(s)
> >|> $
> It's not that bad.  The -f option to set was added to sh in
> system III.  Only the Ultrix sh and the old BSD (v7) sh do not
> have it.

It seems that Ultrix is a real kludge for its sh.  Its test doesn't have -x,
it doesn't support -p for setuids, and no -f.  All of those work on SunOs.

Hrv
--
Hrvoje Niksic             |  Student of electrical engineering

--------------------------------------------------------------
The old shaman said carefully, "You didn't just see two men go through
upside down on a broomstick, shouting and screaming at each other, did
you?" The boy looked at him levelly. "Certainly not," he said. The old man
heaved a sigh of relief. "Thank goodness for that," he said. "Neither did I."
        -- Rincewind and Twoflower take up broomstick flying
           (Terry Pratchett, The Light Fantastic)

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Chet Ram » Wed, 21 Dec 1994 01:12:20





>> >|> $ set -f
>> >|> -f: bad option(s)
>> >|> $
>> It's not that bad.  The -f option to set was added to sh in
>> system III.  Only the Ultrix sh and the old BSD (v7) sh do not
>> have it.

>It seems that Ultrix is a real kludge for its sh.  Its test doesn't have -x,
>it doesn't support -p for setuids, and no -f.  All of those work on SunOs.

The Ultrix sh is the old BSD sh, but of 4.2 BSD vintage.  `Test' is not
builtin to that shell, and it does not have `set -f'.

What version of the SunOS sh has `-p'?  Here's what I get:

odin(2)$ uname -a
SunOS odin 4.1.2 13 sun4m
odin(2)$ sh
${HOST}($SHLVL)\$ set -p
-p: bad option(s)
${HOST}($SHLVL)\$
odin(2)$ sh -p
-p: bad option(s)

Is this a SunOS5 thing?

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


 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Hrvoje Niks » Wed, 21 Dec 1994 08:22:42



Quote:> What version of the SunOS sh has `-p'?  Here's what I get:

Nope, it was a mistake of mine.  Sorry :-(  Anyway, the stuff with -x and -f
remains :(

Hrv
--
Hrvoje Niksic             |  Student of electrical engineering

--------------------------------------------------------------
The old shaman said carefully, "You didn't just see two men go through
upside down on a broomstick, shouting and screaming at each other, did you?"
The boy looked at him levelly. "Certainly not," he said. The old man heaved
a sigh of relief. "Thank goodness for that," he said. "Neither did I."
        -- Rincewind and Twoflower take up broomstick flying
           (Terry Pratchett, The Light Fantastic)

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Musas » Wed, 21 Dec 1994 13:20:41



:
:>Hi... I have a question in shell script, so i will be appreciated if
:>anyone can solve my problem. Here is the code:
:
:>pattern=" dd  *  ddd ?"

        [ snip ]

:>The question is, instead of printing "dd", "*", "dd" and "?",
:>the shell treats * and ? as wildcard chars. That is, it prints

        [ snip ]

        I believe that you can escape any special meaning of a character
(such as wildcards, $, ", etc) by putting a backslash (\) directly in front
of the character.  So it would be...

pattern=" dd \* ddd \?"

hope this helps

        -Jacob

--
      /          "Meddle not in the affairs of dragons, for             \
 *}=={*}>======-  thou art crunchy and go well with ketchup."  -======<{*}=={*
      \                                                                 /

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by Heiner Stev » Thu, 22 Dec 1994 01:14:08



[...]
|> pattern=" dd  *  ddd ?"
|> set $pattern
|> for word
|> do
|>   echo $word
|> done
|>
|> The question is, instead of printing "dd", "*", "dd" and "?",
|> the shell treats * and ? as wildcard chars. That is, it prints

    pattern=' dd  *  ddd ?'
    set -- "$pattern"
    for word
    do
        echo "$word"
    done

Note the single quotes '' in the first, the double quotes in
the second and in the fifth line.

Heiner
--

      -------------------------------------------------------------

    / BinTec Computersysteme GmbH / mine, not BinTec's --       /
   / Willstaetter Str. 30 -------   ...even if they should ;-) /
  / D-90449 Nuernberg    /                                    /

-------------------------------------------------------------

 
 
 

Problem printing "*" and "?" in sh. HELP!

Post by C. A. Ladema » Thu, 22 Dec 1994 07:07:11



Quote:>Hi... I have a question in shell script, so i will be appreciated if
>anyone can solve my problem. Here is the code:

Try:

pattern=" dd  *  ddd ?"

set -f           # disable filename generation

set $pattern
for word
do
        echo $word
done

set +f           # enable filename generation

cal.
--
----------------------------------------------------------------------

    ZLS Software GmbH                         Tel.:  (+49) 6195 900500
     D-65779 Kelkheim                         Fax:   (+49) 6195 900600