|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
If I do this on AIX or Linux (trivial example to illustrate the core
of the problem): echo "A___A" |tr '_' ' ' then I get what I expected to see ("A<space><space><space>A"). Three whitespaces. But if I do this: foo=`echo "A___A" |tr '_' ' ' ` ; echo $foo then I get this "A<space>A" One whitespace. The extra whitespaces are being compressed (as if I were doing tr -s, which I am not, and I have no such alias). How can I assign $foo and have it preserve multiple whitespace??? Thanks! -- David Filmer (http://DavidFilmer.com) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
usenet@DavidFilmer.com wrote:
> If I do this on AIX or Linux (trivial example to illustrate the core > of the problem): > > echo "A___A" |tr '_' ' ' > > then I get what I expected to see ("A<space><space><space>A"). Three > whitespaces. > > But if I do this: > foo=`echo "A___A" |tr '_' ' ' ` ; echo $foo ....; echo "$foo" > then I get this "A<space>A" > > One whitespace. > > The extra whitespaces are being compressed (as if I were doing tr -s, > which I am not, and I have no such alias). > > How can I assign $foo and have it preserve multiple whitespace??? Always quote your variables unless you have a very specific reason not to. Ed. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Nov 7, 7:34 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> ...; echo "$foo" > Always quote your variables unless you have a very specific reason not to. Thanks! That's taboo in Perl... and I was going nuts trying to figure this out. It never ocured to me to quote the var! -- David Filmer (http://DavidFilmer.com) |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
usenet@DavidFilmer.com wrote:
> > On Nov 7, 7:34 pm, Ed Morton <mor...@lsupcaemnt.com> wrote: > > ...; echo "$foo" > > > Always quote your variables unless you have a very specific reason not to. > > Thanks! That's taboo in Perl... and I was going nuts trying to figure > this out. It never ocured to me to quote the var! It is not taboo but unlike the shell it is not required. The FAQ explains the issues: perldoc -q quoting Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod What's wrong with always quoting "$vars"? John -- use Perl; program fulfillment |
|
![]() |
| Outils de la discussion | |
|
|