.bashrc没有正确地使用空格读取环境路径

时间:2013-06-19 08:54:08

标签: android linux bash environment-variables

在我的Ubuntu 13中,我编辑了我的.bashrc,添加了一个环境路径:

export OGRE_ANDROID_ROOT=/home/piperoman/Librerias/Ogre\ Android\ SDK

如果我回显变量,它可以正常工作,但是当我尝试在makefile中使用它时,它没有。我已经使用cd命令进行了测试,结果如下:

$ echo $OGRE_ANDROID_ROOT 
/home/piperoman/Librerias/Ogre Android SDK
$ cd $OGRE_ANDROID_ROOT
bash: cd: /home/piperoman/Librerias/Ogre: No such file or directory

为什么echo有效,但我不能正确地使用命令?

4 个答案:

答案 0 :(得分:9)

简答:Word-splitting

当你有这个

export OGRE_ANDROID_ROOT=/home/piperoman/Librerias/Ogre\ Android\ SDK

环境变量包含“/ home / piperoman / Librerias / Ogre Android SDK”。

如果您使用它而不用引号括起来,Bash会根据IFS环境变量将字符串拆分为单词 - 默认选项卡,空格和换行符。

所以

cd $OGRE_ANDROID_ROOT

相当于

cd "/home/piperoman/Librerias/Ogre" "Android" "SDK"

所以你应该引用它,即"$OGRE_ANDROID_ROOT"

答案 1 :(得分:3)

尝试

cd "$OGRE_ANDROID_ROOT" 

带引号。

答案 2 :(得分:2)

只需添加.bashrc中没有反斜杠的行:

export OGRE_ANDROID_ROOT="/home/piperoman/Librerias/Ogre Android SDK"

然后在需要cd时使用引号来包装变量:

cd "$OGRE_ANDROID_ROOT"

使用export MYT="/home/me/test/my test/"

进行测试

答案 3 :(得分:1)

这是因为文件夹名称之间是空格。在linux中,这些空格通常不会被使用,因为它们不被识别为单个文件夹。

例如

$ mkdir hello\ world                    // will create a folder named hello world
$ cd hello\ world                      // go in to the created folder
$ pwd                                  // display the directory name

这将显示为hello> space<世界

因此环境可用$ OGRE_ANDROID_ROOT设置为/ home / piperoman / Librerias / Ogre而不是/ home / piperoman / Librerias / Ogre Android SDK

  

要解决此错误,请重命名该文件夹,以便删除空格

相关问题