Bash: space in variable value later used as parameter

前端 未结 4 2023
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 03:52

While writing a bash script to help creating polaroid thumbnail using Imagick\'s convert commmand. I encounter a problem. Although, I manage to work around with

4条回答
  •  误落风尘
    2020-12-18 04:36

    Putting backticks around $COMMAND on the last line causes the script to try to execute the output of the command rather than the command itself.

    $ c='echo hi'
    $ `$c`
    hi: command not found
    

    This will work:

    if [[ "$CAPTION" != "" ]]
    then
        convert -caption "$CAPTION" "$IN_FILE" "$OUTFILE"
    else
        convert "$IN_FILE" "$OUTFILE"
    fi
    

提交回复
热议问题