assign command result to variable
am 04.01.2008 15:51:27 von sorg.daniel
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
Re: assign command result to variable
am 04.01.2008 16:07:32 von mik3l3374
On Jan 4, 10:51 pm, sorg.dan...@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
backticks?
TEMP=`$GROUPID | sed -e 's/\./\//g'`
Re: assign command result to variable
am 04.01.2008 16:18:33 von Ed Morton
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.