In my Ubuntu 13 I have edited my .bashrc adding an environment path:
export OGRE_ANDROID_ROOT=/home/piperoman/Librerias/Ogre\ Android\ SDK
If I echo the variable, it works fine, but when I try to use it in a makefile, it does not. I have tested with a cd
command 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 cannot use the variable correctly with commands?
To cd to a directory with spaces in the name, in Bash, you need to add a backslash ( \ ) before the space. In other words, you need to escape the space.
The solutions are to use quotes or the backslash escape character. The escape character is more convenient for single spaces, and quotes are better when there are multiple spaces in a path. You should not mix escaping and quotes.
In order to set a permanent environment variable in Bash, you have to use the export command and add it either to your “. bashrc” file (if this variable is only for you) or to the /etc/environment file if you want all users to have this environment variable.
Short-answer: Word-splitting.
When 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 enclosing in quotes, Bash will split the string into words based on the IFS
environment variable – by default tab, space, and newlines.
So
cd $OGRE_ANDROID_ROOT
is equivalent to
cd "/home/piperoman/Librerias/Ogre" "Android" "SDK"
So you should quote it, i.e. "$OGRE_ANDROID_ROOT"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With