Skip to content

Instantly share code, notes, and snippets.

@imochoa
Last active October 5, 2021 11:48
Show Gist options
  • Save imochoa/f22abbea94c33a4001a5c3875b164e7e to your computer and use it in GitHub Desktop.
Save imochoa/f22abbea94c33a4001a5c3875b164e7e to your computer and use it in GitHub Desktop.
POSIX parent directory path
# https://unix.stackexchange.com/questions/76505/portable-way-to-get-scripts-absolute-path
currpath=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
currdirname=$(dirname $currpath)
currfilename=$(basename $currpath)
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
# And then use them like this in your script:
# .---------- constant part!
# vvvv vvvv-- the code from above
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "I ${RED}love${NC} Stack Overflow\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment