Issue
I see two different ways of adding path in Linux. For example,
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export PATH=/usr/local/cuda/bin:$PATH
While I am clearly aware of the second way, what is first way doing? What are the advantages over the second?
Solution
When PATH
is empty, then:
export PATH=/usr/local/cuda/bin:$PATH
Results in
PATH=/usr/local/cuda/bin:
The empty :<nothing>
is indicates current working directory, reference https://www.gnu.org/software/bash/manual/bash.html#index-PATH . The code added current working directory and cuda to path. This is not intended.
Instead, you want to add a :
only if PATH is not empty. This is what ${PATH:+:${PATH}}
achieves.
Answered By - KamilCuk Answer Checked By - Gilberto Lyons (WPSolving Admin)