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 > printf and shell variable
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

printf and shell variable

Réponse
 
LinkBack Outils de la discussion
Vieux 12/11/2007, 23h16   #1
Farid Hamjavar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut printf and shell variable


Greetings,

In my script I have to process variables whose values
(happen to be file names) contains the '%' character

Since I have no control over how files are named,
I was wondering if there is a way I can get around
the situation which I am emulating through an example below:



# export filename=Hello%20World

# printf $filename
bash: printf: `W': invalid format character




Thanks,
Farid



  Réponse avec citation
Vieux 12/11/2007, 23h44   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf and shell variable

Farid Hamjavar wrote:
> Greetings,
>
> In my script I have to process variables whose values
> (happen to be file names) contains the '%' character
>
> Since I have no control over how files are named,
> I was wondering if there is a way I can get around
> the situation which I am emulating through an example below:
>
>
>
> # export filename=Hello%20World
>
> # printf $filename
> bash: printf: `W': invalid format character


Provide a format string for printf...

$ filename="Hello%20World"
$ printf "%s\n" "$filename"'
Hello%20World


Janis

>
>
>
>
> Thanks,
> Farid
>
>
>

  Réponse avec citation
Vieux 12/11/2007, 23h55   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf and shell variable



On 11/12/2007 5:16 PM, Farid Hamjavar wrote:
> Greetings,
>
> In my script I have to process variables whose values
> (happen to be file names) contains the '%' character
>
> Since I have no control over how files are named,
> I was wondering if there is a way I can get around
> the situation which I am emulating through an example below:
>
>
>
> # export filename=Hello%20World
>
> # printf $filename
> bash: printf: `W': invalid format character


Yes, use printf as the manual page tells you, i.e.:

printf <format> <text>

so in this case you'd do:

printf "%s\n" "$filename"

Regards,

Ed.

  Réponse avec citation
Vieux 12/11/2007, 23h56   #4
Gretch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf and shell variable

In news:Pine.LNX.4.64.0711121611080.17704@chishio.swc p.com,
Farid Hamjavar <hamjavar@unm.edu> wrote:

> In my script I have to process variables whose values
> (happen to be file names) contains the '%' character
>
> Since I have no control over how files are named,
> I was wondering if there is a way I can get around
> the situation which I am emulating through an example below:
>
> # export filename=Hello%20World
> # printf $filename
> bash: printf: `W': invalid format character


Format the output as a string:
printf %s $filename
  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 20h54.


É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,08502 seconds with 12 queries