Bash and filenames with spaces

前端 未结 6 1801
情深已故
情深已故 2020-12-01 03:23

The following is a simple Bash command line:

grep -li \'regex\' \"filename with spaces\" \"filename\"

No problems. Also the following works

6条回答
  •  心在旅途
    2020-12-01 03:28

    Try this:

    (IFS=$'\n'; grep -li 'regex' $(

    IFS is the Internal Field Separator. Setting it to $'\n' tells Bash to use the newline character to delimit filenames. Its default value is $' \t\n' and can be printed using cat -etv <<<"$IFS".

    Enclosing the script in parenthesis starts a subshell so that only commands within the parenthesis are affected by the custom IFS value.

提交回复
热议问题