build argument lists containing whitespace

前端 未结 5 1522
一生所求
一生所求 2020-12-01 13:24

In bash one can escape arguments that contain whitespace.

foo \"a string\"

This also works for arguments to a command or function:

5条回答
  •  青春惊慌失措
    2020-12-01 13:44

    Here is a shorter version which does not require the use of a numeric index:

    (example: building arguments to a find command)

    dir=$1
    shift
    for f in "$@" ; do
        args+=(-iname "*$f*")
    done
    find "$dir" "${args[@]}"
    

提交回复
热议问题