$tmp=/folder1/This Folder Here/randomfile.abc$echo "$tmp" | sed -e 's/ /\ /g'/folder1/This\ Folder\ Here/randomfile.abc
但是一旦我将它传递给变量,sed就不再用反斜杠替换空格:
$tmp=/folder1/This Folder Here/randomfile.abc$location=`echo "$tmp" | sed -e 's/ /\ /g'`$echo $location/folder1/This Folder Here/randomfile.abc
我希望第二双眼睛可以接受我不喜欢的东西.
解决方法 你需要几对反斜杠:sed -e 's/ /\\ /g'
您似乎想引用输入以便将其用作shell输入.没有必要使用sed.你可以使用printf:
$foo="a string with spaces"$printf "%q" "$foo"a\ string\ with\ spaces总结
以上是内存溢出为你收集整理的传递SED替换BASH变量中的参数全部内容,希望文章能够帮你解决传递SED替换BASH变量中的参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)