将路径转换为字符串 bash
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13720241/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert path to string bash
提问by Jetse
I want to put multiple filepaths as a string in bash script, so I can pass this string to another program. When I concatenate these filepaths I get the error: No such file or directory. Bash has to tread this filepath as a string instead of a file...
我想将多个文件路径作为字符串放在 bash 脚本中,这样我就可以将此字符串传递给另一个程序。当我连接这些文件路径时,出现错误:没有这样的文件或目录。Bash 必须将此文件路径视为字符串而不是文件...
Im concatenating this way:
我以这种方式连接:
all=""
for path in $dir/*; do
    filePath="$path/file.txt"
    $all="$all I=$filePath"
done
echo $all
How can I get this output?
我怎样才能得到这个输出?
I=first/file.txt I=second/file.txt etc.
回答by Luca Davanzo
Is just your syntax wrong:
只是你的语法错误:
all=""
for path in $dir/*; do
    filePath="$dir/file.txt"
    all="$all I=$filePath"    #without $
done
echo $all
回答by Jens
Maybe you meant to use path? And don't use $ as a prefix in assignments.
也许你打算使用path? 并且不要在赋值中使用 $ 作为前缀。
all=""
for path in $dir/*; do
    filePath="$path/file.txt"
    all="$all I=$filePath"
done
echo $all

