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 > Variable expansion of a string which includes quoted text
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Variable expansion of a string which includes quoted text

Réponse
 
LinkBack Outils de la discussion
Vieux 09/12/2006, 12h10   #1
Martin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Variable expansion of a string which includes quoted text

Hi all,

I have a problem with variable expansion. I tried this with the bash:

OPTIONS="-e 'ssh host ssh' -PHS" # In one config file

rsync $OPTIONS ... # in a script 'source'-ing the config file

The actual command and arguments are not the problem here, only that
the -e option has an argument with spaces 'ssh host ssh'.
After expanding OPTIONS the single quotes around this argument are not
taken into account by the shell, i.e the command doesn't get that as
one string but as three words:
Arguments to command: -e, 'ssh, host, ssh', -PHS, not: -e, 'ssh host
ssh', -PHS
Because of this the options are parsed wrong by the command.

Is there a way to keep the quoted part of the OPTIONS variable as one
string?

This trick seems to work but I look for something more general and
better:

OPTIONS="-e,ssh host ssh,-PHS"

IFS=","
rsync $OPTIONS ...

  Réponse avec citation
Vieux 09/12/2006, 12h43   #2
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Variable expansion of a string which includes quoted text

Martin wrote:
> Hi all,
>
> I have a problem with variable expansion. I tried this with the bash:
>
> OPTIONS="-e 'ssh host ssh' -PHS" # In one config file
>
> rsync $OPTIONS ... # in a script 'source'-ing the config file
>
> The actual command and arguments are not the problem here, only that
> the -e option has an argument with spaces 'ssh host ssh'.
> After expanding OPTIONS the single quotes around this argument are not
> taken into account by the shell, i.e the command doesn't get that as
> one string but as three words:
> Arguments to command: -e, 'ssh, host, ssh', -PHS, not: -e, 'ssh host
> ssh', -PHS
> Because of this the options are parsed wrong by the command.
>
> Is there a way to keep the quoted part of the OPTIONS variable as one
> string?
>
> This trick seems to work but I look for something more general and
> better:
>
> OPTIONS="-e,ssh host ssh,-PHS"
>
> IFS=","
> rsync $OPTIONS ...
>


eval rsync "$OPTIONS"


--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 09/12/2006, 18h38   #3
Martin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Variable expansion of a string which includes quoted text

Michael Tosch wrote:
> Martin wrote:
> > Hi all,
> >
> > I have a problem with variable expansion. I tried this with the bash:
> >
> > OPTIONS="-e 'ssh host ssh' -PHS" # In one config file
> >
> > rsync $OPTIONS ... # in a script 'source'-ing the config file
> >

>
> eval rsync "$OPTIONS"
>


Thanks, this works fine.
I should have known this by myself!

Martin

  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 02h15.


É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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,30558 seconds with 11 queries