我有一个文件config.ini:
repo_path=ssh://git@localhost:10022/root/
dir_path=/home/vagrant/workspace/
以及一个“ script.sh”,用于从该文件导出和连接,如下所示:
while read -r line; do export $line; done <config.ini
repo_name=$1
repo_path=$repo_path$repo_name'.git'
dir_path=$dir_path/$repo_name
echo $repo_path
echo $dir_path
所以当我运行脚本时:
./script.sh sample
输出:
sample.gitlocalhost:10022/root/
/sampleagrant/workspace/
预期输出:
ssh://git@localhost:10022/root/sample.git
/home/vagrant/workspace/sample
一个合理的解释是您的数据中嵌入了回车符。
sample.gitlocalhost:10022/root/
^^^^^^^^^^
也就是说,字符串如下(使用C语言字符串文字表示法):
"ssh://git@localhost:10022/root/\rsample.git"
注意\r
表示回车
当您将其发送到终端时,回车导致光标移动到行首,从而sample.git
覆盖了ssh://...
前缀。
要调试这种“神秘输出”问题,可以将命令的输出通过管道传递给二进制转储实用程序,例如od
:
echo $strange | od -t c # see characters with backslash notation, or -t x1 for hex
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句