Search code examples
bash.profiletilde-expansion

Tilde Expansion Doesn't Work When I Logged Into GUI


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!


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