Question

I'm using Ubuntu 11.10 and I have a strange problem.

I have a few exports in my .profile file:
export ANDROID_SDK_ROOT=~/workspace/android-sdk-linux_x86
export ANDROID_NDK_ROOT=~/workspace/android-ndk-r7
etc...

However, when I log on into GUI, open up my terminal and do echo $ANDROID_SDK_ROOT, it shows ~/workspace/android-sdk-linux_x86 rather than /home/brian/workspace/android-sdk-linux_x86.

Since it shows ~/workspace/android-sdk-linux_x86, it seems like .profile is read upon logging into GUI, but I'm not sure why tilde is not expanded.

If I run ". ~/.profile" in the terminal and check echo $ANDROID_SDK_ROOT, it shows /home/brian/workspace/android-sdk-linux_x86 fine. It's quite strange and I'm not sure why.

If I log into CUI (command user interface), when I do echo $ANDROID_SDK_ROOT, it prints /home/brian/workspace/android-sdk-linux_x86 as expected. So the problem only happens when I log into GUI.

Does anybody have any clue what's going on? I don't have .bash_profile in my home directory (I read somewhere that if I have .bash_profile, .profile is not read so I made sure .bash_profile does not exist; and I'm pretty sure .profile is read because it printed ~/workspace/android-sdk-linux_x86 when I did echo $ANDROID_SDK_ROOT). If you know what I might have done wrong, please shed some light.

Thanks!

Was it helpful?

Solution

Using tilde expansion with export is shell dependent (since some shells do not qualify assignment in export command as shell variable assignment). Thus, it's better to rewrite it as:

ANDROID_SDK_ROOT=~/workspace/android-sdk-linux_x86
export ANDROID_SDK_ROOT
ANDROID_NDK_ROOT=~/workspace/android-ndk-r7
export ANDROID_NDK_ROOT

OTHER TIPS

In some cases (depending on the shell), ~ may be expanded only at the beginning of a word. You can work around it by using $HOME instead:

export ANDROID_SDK_ROOT=$HOME/workspace/android-sdk-linux_x86
export ANDROID_NDK_ROOT=$HOME/workspace/android-ndk-r7

(Note that this won't work for the ~username syntax, just for ~ expanding to your own home directory.)

In particular, bash does expand ~ in this context, but dash doesn't. On Ubuntu, /bin/sh is a symbolic link to dash; /bin/sh is the shell used by default for a lot of non-interactive activities.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top