marjun
marjun

Reputation: 726

how to assign echo value to a variable in shell

Im tring to assign echo value which to a variable but im getting error

Var='(echo $2 | sed -e 's/,/: chararray /g'|  sed -e 's/$/: chararray/')'
echo $var

Input :  sh load.sh file 1,2,3,4
Error load.sh: line 1: chararray: command not found

Upvotes: 8

Views: 30910

Answers (1)

Antxon
Antxon

Reputation: 1943

Var=$(echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/')
echo "$Var"

OR

Var=`echo "$2" | sed -e 's/,/: chararray /g' | sed -e 's/$/: chararray/'`
echo "$Var"

Use either $(…) or perhaps `…` backtick notation. However, the backtick notation is deprecated and should be avoided. Also, check the comments by mmgross, Etan Reisner and svlasov to your question. They are all correct.

Upvotes: 11

Related Questions