Why echo a backticks-row?

后端 未结 1 1045
死守一世寂寞
死守一世寂寞 2021-01-25 06:03

I \"inherited\" some code in a project, and in one of the Bash scripts, they use echo on a backticks-row, like:

#!/bin/bash
echo `/path/command argu         


        
相关标签:
1条回答
  • 2021-01-25 06:07

    It doesn't look particularly useful in its current form but one side-effect of using echo with (unquoted) backticks is that whitespace between words is lost. This is because of word splitting - every word in the output of the command is treated as a separate argument to echo, which just outputs them separated by a single space. For example:

    $ echo "a   b c"
    a   b c
    $ echo `echo "a   b c"`
    a b c
    

    Note that this applies to all types of whitespace such as tab characters and newlines.

    I'm not sure why you'd want to do this deliberately! Personally, I'd be tempted to just run the command normally.

    0 讨论(0)
提交回复
热议问题