.bashrc incorrectly reads environment path with spaces

In my Ubuntu 13, I edited my .bashrc adding an environment path:

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

If I repeat the variable, it works fine, but when I try to use it in the makefile, it is not. I tested the cd and this is the result:

 $ 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 

Why does echo work, but I can't use the variable with commands correctly?

+6
source share
4 answers

Short answer: Word-splitting .

If you have this

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

The environmental variable contains "/ home / piperoman / Librerias / Ogre Android SDK".

If you use it without quotation marks, Bash will split the line into words based on the IFS environment variable - by default, the tab, space and newlines.

So

 cd $OGRE_ANDROID_ROOT 

equivalently

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

So you should quote it, i.e. "$OGRE_ANDROID_ROOT"

+9
source

Try

 cd "$OGRE_ANDROID_ROOT" 

with quotes.

+3
source

Just add a line to .bashrc without a backslash:

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

and then use quotation marks to wrap the variable if you want cd :

 cd "$OGRE_ANDROID_ROOT" 

Tested with export MYT="/home/me/test/my test/"

+2
source

This is due to the fact that the folder name as spaces between spaces. On linux, these spaces are usually not used, as they are not identified as a single folder.

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

this will display as hello> space <world Therefore, the vairable $ OGRE_ANDROID_ROOT environment is set as / home / piperoman / Librerias / Ogre, and not / home / piperoman / Librerias / Ogre Android SDK

To resolve this error, rename the folder to remove spaces.

+1
source

Source: https://habr.com/ru/post/947633/


All Articles