Bash: Check if argument was passed to script
25 October 2023 (Updated 25 October 2023)
Check if the first argument was passed
#!/bin/bash
if [ -z "$1" ]; then
echo "No first argument was passed."
else
echo "The first argument is: $1"
fi
Check if any arguments were passed
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No arguments were passed."
else
echo "The following arguments were passed: $@"
fi
Tagged:
Bash
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment