说我有这个文件:
hello
world
hello world
Run Code Online (Sandbox Code Playgroud)
这个程序
#!/bin/bash
for i in $(cat $1); do
echo "tester: $i"
done
Run Code Online (Sandbox Code Playgroud)
产出
tester: hello
tester: world
tester: hello
tester: world
Run Code Online (Sandbox Code Playgroud)
我希望for
对每一行进行迭代,分别忽略空格,即最后两行应替换为
tester: hello world
Run Code Online (Sandbox Code Playgroud)
使用引号for i in "$(cat $1)";
会立即i
分配整个文件。我应该改变什么?