[gull] Truc et astuces: bash: jouons avec les variables et eval
Jean-Pierre Rupp
jpierre at xeno-genesis.com
Thu Nov 3 23:01:30 CET 2011
Oh my!
Nice hacks!
Le 2 novembre 2011 15:26, Félix Hauri <felix at f-hauri.ch> a écrit :
> Bonjour,
>
> Petite démo, à toutes fins utiles (c'est du bash >=2.05b)
>
> $ eval $(
> env LANG=fr_CH date +"$(
> date --help |
> sed -ne '/^ %[^ %]\{1,4\} .*$/{
> s/^ %\([^ ]*\) .*$/\1/;
> y|:|_|;
> p;
> y|_|:|;
> p}' |
> xargs printf "DATE_%s=\"%%%s\" "
> )"
> )
>
> $ echo $DATE_X
> 15:14:39
> $ echo $DATE_x
> 02. 11. 11
> $ echo $DATE_{x,X}
> 02. 11. 11 15:14:39
> $ echo $DATE_{a,d,b,Y,T}
> mer 02 nov 2011 15:14:39
>
> Jusque là, c'est bonnard, mais alors...
>
> Si
> $ printf ".%s.\n" $DATE_{X,x,,c}
> .15:14:39.
> .02..
> .11..
> .11.
> .mer.
> .02.
> .nov.
> .2011.
> .15:14:39.
> .CET.
>
> ne donne pas le resultat escompté, on s'en sort avec:
>
> $ eval printf\ \".%s.\\n\"\ \"\$\{DATE_{X,x,,c}\}\"\;
> .15:14:39.
> .02. 11. 11.
> ..
> .mer 02 nov 2011 15:14:39 CET.
>
> J'espère m'être fait comprendre...
>
> --
> Félix Hauri - <felix at f-hauri.ch> - http://www.f-hauri.ch
> _______________________________________________
> gull mailing list
> gull at forum.linux-gull.ch
> http://forum.linux-gull.ch/mailman/listinfo/gull
>
More information about the gull
mailing list