我有一个文件,其中包含以下命令。
#!/bin/csh -f
echo "test test" //echo test [dobule space] test
set a = "test test" //set a = test [dobule space] test
echo $a
输出如下。
测试[双倍空间]测试
测试[单个空格]测试
当我将 value 设置为 a 时,如何将双空格替换为单个空格?
感谢任何帮助。
最佳答案
How does the double space get replaced with a single space when I set value to a?
不,它不会被单个空格替换。这是因为您没有在 echo
中使用引号。使用:
echo "$a"
获取双倍行距字符串。
如果您不引用变量,Shell 默认会将多个空格修剪为一个空格。即使这也将是单个空格:
s='a b'
echo $s
a b
但带引号:
echo "$s"
a b
<小时/>
编辑:根据下面的评论,您可以在 csh 中执行此操作:
set QUERY = "select p.path from path p, file f where p.pathid=f.pathid and f.fileid=1234"
set dir = "`/usr/etc/venture/bin/mysql -BN -uroot -***** ****-e '$QUERY'`"
echo "$dir"
关于csh - 双空格自动替换为单空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27982933/