How to pass command line arguments with spaces through a variable in bash

前端 未结 2 385
广开言路
广开言路 2021-01-19 10:58

What I\'m trying to achieve is to read command line arguments from a file and invoke a command using them. So essentially I need to pass the arguments through a bash variabl

2条回答
  •  时光取名叫无心
    2021-01-19 11:42

    Use command substitution, to expand the file contents to the command,

    /some/command "$(

    As an example,

    cat file
    "aaa bbb" "xxx yyy"
    

    using printf on it INCORRECTLY with cat will produce

    printf "%s\n" $(cat file)
    "aaa
    bbb"
    "xxx
    yyy"
    

    With proper quoting present, arguments are sent as such without getting split.

    printf "%s\n" "$(

提交回复
热议问题