0

I'm working on Ubuntu 16.04 LTS and I need to add CUDA PATH and LD_LIBRARY_PATH. Then I read a blog saying this can be done by adding these two lines in ~/.vimrc

version 1:

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

And I also read another version:

version 2:

export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64:$LD_LIBRARY_PATH

And I'm not sure the differences between them, especially the confusing nested $PATH in version 1.

1 Answer 1

1

Version 1

Version 1 uses special #!/bin/bash shell expansion features (see bash reference manual):

${parameter:+word}

If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

In other words, the delimiter : and the current $PATH are only appended to /usr/local/cuda-8.0/bin if and only if $PATH isn't empty.


Version 2

On the other hand, version 2 only uses #!/bin/sh compliant features. Contrary to version 1, if $PATH is empty, your exported variable will look like this: /usr/local/cuda-8.0/bin: (Note the : at the end).

Which version you prefer hence depends on the shell installed on your system(s). If you want to be as compatible as possible, stick to version 2. If you are sure that all your systems have bash installed, you can use version 1.

Sign up to request clarification or add additional context in comments.

1 Comment

Got it. As the rule goes, if the original $PATH is not null, then substitution is performed, we get :$PATH, which is added at the end of cuda bin path. And if $PATH is null, append nothing .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.