Prefixing variable assignment doesn't work with echo

后端 未结 1 1618
孤城傲影
孤城傲影 2021-01-15 00:58

As far as I know, if you prefix a bash command with variable assignment the variable will take effect immediately. And it will only have effect within that command.

相关标签:
1条回答
  • 2021-01-15 01:39

    The variable will be passed in the environment of the command following it, not when the command is being evaluated (expanded). Any variable expansion will be done earlier by shell.

    $ V=1 env | grep V=
    V=1
    

    To get it working:

    $ V=1; echo $V
    1
    
    0 讨论(0)
提交回复
热议问题