assign command result to variable

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
sorg.daniel [ Fr, 04 Januar 2008 15:51 ] [ ID #1899399 ]

Re: assign command result to variable

On Jan 4, 10:51 pm, sorg.dan... [at] 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'`
mik3l3374 [ Fr, 04 Januar 2008 16:07 ] [ ID #1899402 ]

Re: assign command result to variable

On 1/4/2008 8:51 AM, sorg.daniel [at] 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.
Ed Morton [ Fr, 04 Januar 2008 16:18 ] [ ID #1899405 ]
Linux » comp.unix.shell » assign command result to variable

Vorheriges Thema: [newbie]remove .svn directory
Nächstes Thema: Regular expression with egrep question...