Reputation: 1653
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
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:
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.
Upvotes: 0
Views: 112
Reputation: 866
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.
Upvotes: 1