Home > Software engineering >  echo does not print command output as expected
echo does not print command output as expected

Time:10-26

This following command prints nothing on my machine

echo `python3.8 -c 'print ("*"*10)'`

whereas

python3.8 -c 'print ("*"*10)' 

does. Why?

CodePudding user response:

The first example does command substitution for the argument to echo and is equivalent to the command echo **********. This happens to output a list of directory contents, since ********** seems to be equivalent to *1 and is expanded by the shell.

If you want to prevent the shell to expand **********, you need to quote it:

echo "`python3.8 -c 'print ("*"*10)'`"

which is equivalent to echo "**********".


1don't quote me on that (pun intended)

CodePudding user response:

`expr` means to evaluate the contents between ' as a command and replace it with the result.

`print(*)` is equal to ` * ` which is evaluated as all the files in the current directory

The output really depends on the machine used

  •  Tags:  
  • bash
  • Related