How to properly nest Bash backticks

前端 未结 5 1101
死守一世寂寞
死守一世寂寞 2020-12-07 18:31

Either I missed some backlash or backlashing does not seem to work with too much programmer-quote-looping.

$ echo \"hello1-`echo hello2-\\`echo hello3-\\`ech         


        
5条回答
  •  忘掉有多难
    2020-12-07 19:02

    Any time you want to evaluate a command use command substitution:

    $(command)
    

    Any time you want to evaluate an arithmetic expression use expression substitution:

    $((expr))
    

    You can nest these like this:

    Let's say file1.txt is 30 lines long and file2.txt is 10 lines long, than you can evaluate an expression like this:

    $(( $(wc -l file1.txt) - $(wc -l file2.txt) ))
    

    which would output 20 ( the difference in number of lines between two files).

提交回复
热议问题