PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > backticks zapping whitespace - arrgh
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

backticks zapping whitespace - arrgh

Réponse
 
LinkBack Outils de la discussion
Vieux 08/11/2007, 03h22   #1
usenet@DavidFilmer.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut backticks zapping whitespace - arrgh

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)

  Réponse avec citation
Vieux 08/11/2007, 03h34   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: backticks zapping whitespace - arrgh

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.
  Réponse avec citation
Vieux 08/11/2007, 05h18   #3
usenet@DavidFilmer.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: backticks zapping whitespace - arrgh

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)

  Réponse avec citation
Vieux 08/11/2007, 06h15   #4
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: backticks zapping whitespace - arrgh

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10905 seconds with 12 queries