Last active
March 6, 2023 12:11
-
-
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.
This file contains hidden or 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
| #!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