What is the benefit of using $() instead of backticks in shell scripts?

后端 未结 8 998
梦谈多话
梦谈多话 2020-11-22 05:05

There are two ways to capture the output of command line in bash:

  1. Legacy Bourne shell backticks ``:

    var=`command`
             
    
    
            
8条回答
  •  感情败类
    2020-11-22 05:51

    Suppose you want to find the lib directory corresponding to where gcc is installed. You have a choice:

    libdir=$(dirname $(dirname $(which gcc)))/lib
    
    libdir=`dirname \`dirname \\\`which gcc\\\`\``/lib
    

    The first is easier than the second - use the first.

提交回复
热议问题