Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash中for循环的输出_Bash_Shell - Fatal编程技术网

bash中for循环的输出

bash中for循环的输出,bash,shell,Bash,Shell,我在while循环中运行for循环 作为参数传递的文件包含以下内容: peter roger casie 我试图创建一个路径来测试文件a、b、c、d、e是否存在 我希望输出是 /peter/a /peter/b 等等 相反,我得到了 /aeter /beter 等等 在这里我需要了解什么?请在下面查找代码- 代码: 读取文件行时;做 x=$fileLine 因为我在b c d e 做 echo/$x/$i 完成 已完成

我在while循环中运行for循环

作为参数传递的文件包含以下内容:

peter
roger
casie
我试图创建一个路径来测试文件a、b、c、d、e是否存在

我希望输出是

/peter/a
/peter/b
等等

相反,我得到了

/aeter
/beter
等等

在这里我需要了解什么?请在下面查找代码-

代码:

读取文件行时;做
x=$fileLine
因为我在b c d e
做
echo/$x/$i
完成
已完成<$1

显然,您的输入文件使用的是windows的行尾格式
\r\n
读取
将删除
\n
,但保留
\r
。打印字符串
/$x/$i
时,“回车”返回到
x
字符串末尾的行首,在
x
的斜杠顶部打印斜杠,并在
x
的第一个字母上打印
i
的字母

您可以将
x=$fileLine
行替换为

x=${fileLine%?}

这将删除最后一个字符。

适用于bash 4.2.8和Ubuntu 11.04。
x=${fileLine%?}