Variable containing multiple args with quotes in Bash

后端 未结 4 1415
渐次进展
渐次进展 2020-11-28 05:59

I generate a bash variable containing all my args and those args contain spaces. When I launch a command with those args - eg. ls $args - quotes are not correctly interprete

4条回答
  •  -上瘾入骨i
    2020-11-28 06:45

    Use set to set your variables as positional parameters; then quoting will be preserved if you refer to them via "$@" or "$1", "$2", etc. Make sure to use double quotes around your variable names.

    set -- "$f1" "$f2"
    touch "$@"
    ls "$@"
    rm "$@"
    

提交回复
热议问题