考虑以下示例脚本:
请注意以下示例脚本:
#!/bin/sh
do_something() {
echo $@
return 1
}
cat <<EOF > sample.text
This is a sample text
It serves no other purpose
EOF
cat sample.text | while read arg1 arg2 arg3 arg4 arg5; do
ret=0
do_something "$arg1" "$sarg2" "$arg3" "$arg4" "$arg5" <&3 || ret=$?
done 3<&1
重定向 stdout
作为文件描述符 3 的输入的目的是什么?
至少在 Bash
中,如果省略了它似乎没有任何区别。如果在除 bash
以外的任何其他 shell 中执行,它是否有任何影响?
更新
对于那些想知道这是从哪里来的人,这是来自 Debian 的 cryptdisks_start
脚本的简化示例。
do_something()
没有使用标准输入,所以<&3 == 0<&3
没有任何区别,正如你所观察到的那样。 - cxwcryptdisks_start
(请参见更新)。我希望我没有过于简化问题。 - user4918296