bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Word-splitting limitation with shell variables


From: Andreas Schwab
Subject: Re: Word-splitting limitation with shell variables
Date: 20 Apr 2001 16:48:32 +0200
User-agent: Gnus/5.090002 (Oort Gnus v0.02) Emacs/21.0.103

address@hidden (Mike Paul) writes:

|> Description:
|>         When evaluating the contents of a shell variable as a command string,
|>         there doesn't seem to be any way to cause multiple groups of
|>         space-separated characters to be treated as a single word, as can be
|>         done in an interactive shell by surrounding them with quotes.
|>         Evaluating a variable whose value _contains_ quotes ought to produce
|>         this behavior, I would think, but it doesn't.

You are not _evaluating_ the variable, but only _expanding_ it.  Expanding
a variable does not cause reevaluation, ie. the value is not rescanned for
meta characters.

|> Repeat-By:
|>      In an interactive shell:
|>         foo "filename containing spaces"
|>           passes "foo" in argv[0], "filename containing spaces" in argv[1]
|>           (correct behavior)
|> 
|>         In a script:
|>         cmd="foo \"filename containing spaces\"" ; ${cmd}
|>           passes "foo" in argv[0], "\"filename" in argv[1],
|>           "containing" in argv[2], and "spaces\"" in argv[3]

This is correct.  The variable cmd is expanded and the resulting value is
word splitted.  If you want to evaluate the contents of a variable use

$ eval "${cmd}"

Andreas.

-- 
Andreas Schwab                                  "And now for something
SuSE Labs                                        completely different."
address@hidden
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5



reply via email to

[Prev in Thread] Current Thread [Next in Thread]