Afficher un message
Vieux 04/01/2008, 16h18   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: assign command result to variable



On 1/4/2008 8:51 AM, sorg.daniel@googlemail.com wrote:
> Hi,
>
> i'd like the result of the following command:
>
> $GROUPID | sed -e 's/\./\//g'
>
> to assign to a variable:
>
> TEMP="$GROUPID | sed -e 's/\./\//g'" ???
> or
> TEMP=[$GROUPID | sed -e 's/\./\//g'] ???
>
> What is the correct command?
>
> Thanks in advance!
> Daniel


The syntax is:

variable=`command arguments`

or:

variable=$(command arguments)

so you could use:

TEMP=$(echo "$GROUPID" | sed -e 's/\./\//g')

Using sed to do the subsitution may not be the most efficient way to do it,
depending on which shell you're using, e.g. in bash:

$ x="a:b:c"
$ y="${x//:/,}"
$ echo "$y"
a,b,c

so you may be able to just do:

TEMP="${GROUPID//.//}"

Note also that by convention all-upper-case names are only used for exported
variables.

Ed.

  Réponse avec citation
 
Page generated in 0,08048 seconds with 9 queries