Last active
February 24, 2022 09:25
-
-
Save kylewlacy/aa3fe9be40b14375a26bd3614c99e7bc to your computer and use it in GitHub Desktop.
How to prepend or append to a variable in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prepend to a variable | |
export PATH=/foo${PATH:+:$PATH} # Set path to "/foo:$PATH", or "/foo" if $PATH is empty | |
# Append to a variable | |
export PATH=${PATH:+$PATH:}/foo # Set path to "$PATH:/foo", or "/foo" if $PATH is empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment