Can I use ECHO to execute commands? Can I use ECHO to execute commands? linux linux

Can I use ECHO to execute commands?


Just put your command into parenthesis like this:

echo $(ls)

You can also have text before the command

echo "The date is $(date)"

For Example

echo "Enter Text Here $(Command Here)"


A simple way that won't need modification of your script would be to pipe the command's output to another bash instance. Like this:

yourscript | bash -

The - tells bash that it should read commands from stdin.


However, if you are not searching for a quick solution, it is possible to build and execute the command dynamically as well. Like this:

cmd="ls"if [ "foo" != "bar" ] ; then    cmd="$cmd -a"then# ... and so on# now execute it:$cmd


You can use eval to execute a string:

eval $cmdstring