bash > $(cmd)と`cmd`の違い


動作環境: CentOS 6.5 + bash

bashでコマンドの結果を変数に入れる時

[code]

    val=$(cmd)
    
[/code]

と

[code]

    val=`cmd`
    
[/code]

の書き方があるようですが、この二者の違いはあるのでしょうか? 単に好みの問題でどちらかを使えばいいものでしょうか?

片方にはできて、もう片方にはできないような処理があるのでしょうか?




`bash(1)` から引用します。

> Command Substitution
>
> Command substitution allows the output of a command to replace the command
> name. There are two forms:
>
> $(command)  
>  or  
>  `command`
>
> When the old-style backquote form of substitution is used, backslash retains
> its literal meaning except when followed by $, `, or . The first backquote
> not preceded by a backslash terminates the command substitution. When using
> the $(command) form, all characters between the parentheses make up the
> command; none are treated specially.
>
> Command substitutions may be nested. To nest when using the backquoted form,
> escape the inner backquotes with backslashes.
[code]

    $ echo `echo \``
    bash: command substitution: line 1: unexpected EOF while looking for matching ``'
    bash: command substitution: line 2: syntax error: unexpected end of file
    $ echo `echo \\\``
    `
    $ echo $(echo \`)
    `
    
    $ echo `echo `echo "xyz"``
    echo xyz
    $ echo `echo \`echo "xyz"\``
    xyz
    $ echo $(echo $(echo "xyz"))
    xyz
    
[/code]




`bash(1)` から引用します。

> Command Substitution
>
> Command substitution allows the output of a command to replace the command
> name. There are two forms:
>
> $(command)  
>  or  
>  `command`
>
> When the old-style backquote form of substitution is used, backslash retains
> its literal meaning except when followed by $, `, or . The first backquote
> not preceded by a backslash terminates the command substitution. When using
> the $(command) form, all characters between the parentheses make up the
> command; none are treated specially.
>
> Command substitutions may be nested. To nest when using the backquoted form,
> escape the inner backquotes with backslashes.
[code]

    $ echo `echo \``
    bash: command substitution: line 1: unexpected EOF while looking for matching ``'
    bash: command substitution: line 2: syntax error: unexpected end of file
    $ echo `echo \\\``
    `
    $ echo $(echo \`)
    `
    
    $ echo `echo `echo "xyz"``
    echo xyz
    $ echo `echo \`echo "xyz"\``
    xyz
    $ echo $(echo $(echo "xyz"))
    xyz
    
[/code]

