读取值中包含 space 个字符的变量
Read variable that has space character in its value
我有一些路径存储在变量中(变量名 -> 测试)
echo "${test}"
结果:
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
我想转义第二条路径中的 "space" 字符并获取每条路径的所有者,我正在使用以下命令:
stat -c '%U' ${test} , works for 1st and 3rd path.
如何使第二条路径起作用?提前致谢。
使用 while
结构获取每个文件名,每行一个:
while IFS= read -r f; do stat -c '%U' "$f"; done <<<"$test"
示例:
$ echo "$test"
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
$ while IFS= read -r f; do echo "$f"; done <<<"$test"
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
我有一些路径存储在变量中(变量名 -> 测试)
echo "${test}"
结果:
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
我想转义第二条路径中的 "space" 字符并获取每条路径的所有者,我正在使用以下命令:
stat -c '%U' ${test} , works for 1st and 3rd path.
如何使第二条路径起作用?提前致谢。
使用 while
结构获取每个文件名,每行一个:
while IFS= read -r f; do stat -c '%U' "$f"; done <<<"$test"
示例:
$ echo "$test"
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
$ while IFS= read -r f; do echo "$f"; done <<<"$test"
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3