How can I store a command in a variable in a shell script? October 24, 2022 by Tarik Use eval: x="ls | wc" eval "$x" y=$(eval "$x") echo "$y"