command as variable bash code example
Example 1: store result of command in variable bash
variable=$(command [option…] argument1 arguments2 …)
Example 2: assign a variable in bash
echo
a=879
echo "The value of \"a\" is $a."
let a=16+5
echo "The value of \"a\" is now $a."
echo
echo -n "Values of \"a\" in the loop are: "
for a in 7 8 9 11
do
echo -n "$a "
done
echo
echo
echo -n "Enter \"a\" "
read a
echo "The value of \"a\" is now $a."
echo
exit 0
Example 3: bash command in variable
var=$(command)
var=$(echo 'hi')
var=$(ls)