Skip to content

Instantly share code, notes, and snippets.

@mikaelvesavuori
Last active March 6, 2023 12:11
Show Gist options
  • Save mikaelvesavuori/971469deec2b014e0d073f68c8c53537 to your computer and use it in GitHub Desktop.
Save mikaelvesavuori/971469deec2b014e0d073f68c8c53537 to your computer and use it in GitHub Desktop.
Demonstration of Bash input values, assignment, and null checking with an "echo name" example.
#!bin/bash
set -o pipefail
# Assign first value to a named global variable
NAME="${1}"
# Exit with an error if not set
if [[ -z $NAME ]]; then echo "You need to call this with a value!" && exit 1; fi
# Echo first value coming into function
function echoName() {
echo "Hello there, $1!"
}
echoName $NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment