我有一些路径保存在一个变量(变量名 - >测试)读变量
echo "${test}"
结果:
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
我想逃避的“空间”字符在第二个路径,并获得每个路径的所有者,我使用以下命令:
stat -c '%U' ${test} , works for 1st and 3rd path.
如何使这项工作为2 nd路径?提前致谢。
我有一些路径保存在一个变量(变量名 - >测试)读变量
echo "${test}"
结果:
/abc/pqr/filepath1
/abc/pqr/lmn/file path2
/abc/pqr/rst/filepath3
我想逃避的“空间”字符在第二个路径,并获得每个路径的所有者,我使用以下命令:
stat -c '%U' ${test} , works for 1st and 3rd path.
如何使这项工作为2 nd路径?提前致谢。
使用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
你必须在一个变量一个字符串的所有路径?这似乎是它可能是一个更好的地方使用数组 –
你如何获得'$测试'这些路径? – anubhava