Shell – What’s the right way to set “dynamic” PATH in bash? (for android sdk)

pathshellsoftware installation

I have android sdk installed, and I want the binaries in build-tools/android-VERSION to be available in PATH, so I add few lines:

ANDROID_SDK=/Application/Binaries/adt-bundle-linux-x86_64-20140321/sdk/
ANDROID_PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_SDK/build-tools/android-4.4.2/

Here's the problem, I might update the SDK at any time, so build-tools/android-4.4.2/ might change upon that. If so I would have to edit the file again and update the android-version part in $PATH

So I changed the profile to something like this,

ANDROID_SDK=/Application/Binaries/adt-bundle-linux-x86_64-20140321/sdk/
ANDROID_PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
for x in $ANDROID_SDK/build-tools/android-*/; do
    export PATH=$PATH:$x
done

That looks dumb, any better way to write it?

Best Answer

The ideal way is creating a soft link directory called adt, and re-creating it after SDK changes.

Thus, your PATH will stay the same.

Related Question