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
$ FILES=`sudo find . -type f -print | wc -l` $ echo "There are $FILES in the current working directory." That's it for now, in this article, we explained the methods of assigning the output of a shell command to a variable. You can add your thoughts to this post via the feedback section below.
Two commands, `echo` and `who` are used in this example as the nested command. Here, `who` command will execute first that print the user's information of the currently logged in user. The output of the `who` command will execute by `echo` command and the output of `echo` will store into the variable $var.
We can declare a variable as a variable name followed by assigning operator (=) and the value, which may be a character or string or a number or a special character. There should not be a space between the assignment operator and the variable name, and the corresponding value.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With