May 2017
Beginner
552 pages
28h 47m
English
The prepend() function first confirms that the directory specified by the second parameter to the function exists. If it does, the eval expression sets the variable, with the name in the first parameter equal to the second parameter string, followed by : (the path separator), and then the original value for the variable.
If the variable is empty when we try to prepend, there will be a trailing : at the end. To fix this, modify the function to this:
prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; }