简体   繁体   English

echo无法正确回显该值-没有双引号的BASH Linux

[英]echo not echoing the value correctly - BASH Linux without double quotes

Can someone please point out what shenzie I could have done here?? 有人可以指出我在这里可以做什么吗? PS : Restarting a new shell/session doesn't recreate this issue. PS :重新启动新的外壳程序/会话不会重新创建此问题。

[trinley@linuxserversb12 2]$ echo $gradle_HOME
/home/gradle/gradle- .6
[trinley@linuxserversb12 2]$ echo "$gradle_HOME"
/home/gradle/gradle-1.6

[trinley@linuxserversb12 2]$ echo $gradle_HOME; cd $_
/home/gradle/gradle- .6
-bash: cd: .6: No such file or directory

[trinley@linuxserversb12 2]$ echo "$gradle_HOME"; cd $_
/home/gradle/gradle-1.6
-bash: cd: /home/gradle/gradle-: No such file or directory

[trinley@linuxserversb12 2]$ echo "$gradle_HOME"; cd "$_"
/home/gradle/gradle-1.6

[trinley@linuxserversb12 gradle-1.6]$ pwd
/home/gradle/gradle-1.6

[trinley@linuxserversb12 gradle-1.6]$ echo $gradle_HOME; cd "$_"
/home/gradle/gradle- .6
-bash: cd: .6: No such file or directory

Your IFS variable was set to 1 or something that includes it. 您的IFS变量设置为1或包含它的值。 This causes word splitting to your variables that includes 1 as a separator. 这将导致单词拆分为包含1作为分隔符的变量。

Set it back with IFS=$' \\t\\n' . IFS=$' \\t\\n'

Setting IFS=" " solved the issue. 设置IFS =“”解决了此问题。 It was not set to 1 or anything other than a newline char '\\012' 它未设置为1或换行符'\\ 012'以外的任何其他值

IFS was set to newline character ie IFS设置为换行符,即

[trinley@linuxserversb12 gradle-1.6]$ echo $IFS - "'$IFS'"
    - '\012'

Setting is back to a single space, solved the issue. 设置又回到一个空格,解决了这个问题。

export IFS=" "
$ echo $GRADLE_HOME; cd $_; echo; pwd
/home/gradle/gradle-1.6

/home/gradle/gradle-1.6
$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM