作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设一个文件 file
多行。
$ cat file
foo
bar
baz
$ while IFS= read -r line; do
$ echo $line
$ # do stuff
$ done < file
foo
bar
baz
$ MY_VAR=$(cat file)
$ while IFS= read -r line; do
$ echo $line
$ # do stuff
$ done < $(echo "$MY_VAR")
bash: $(echo "$MY_VAR"): ambiguous redirect
最佳答案
您有多种选择:
done <<<"$MY_VAR"
/bin/sh
一起使用):done <<EOF
$MY_VAR
EOF
printf
而不是 echo
使得它在支持它的 shell 中更具可预测性;参见 POSIX spec for echo
中的 APPLICATION USAGE 注释): done < <(printf '%s\n' "$MY_VAR")
关于bash - bash中变量的while循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44767772/
COW 不是奶牛,是 Copy-On-Write 的缩写,这是一种是复制但也不完全是复制的技术。 一般来说复制就是创建出完全相同的两份,两份是独立的: 但是,有的时候复制这件事没多大必要
我是一名优秀的程序员,十分优秀!