Skip to content

Instantly share code, notes, and snippets.

@kylewlacy
Last active February 24, 2022 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylewlacy/aa3fe9be40b14375a26bd3614c99e7bc to your computer and use it in GitHub Desktop.
Save kylewlacy/aa3fe9be40b14375a26bd3614c99e7bc to your computer and use it in GitHub Desktop.
How to prepend or append to a variable in bash
# 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