pass arguments to function bash code example
Example 1: pass parameters to bash script
# Run the script with the arguments as you would for
# every other command.
# Example: ./script.sh arg1 arg2
#!/bin/sh
echo "argument1: $1"
echo "argument2: $2"
# Output:
# argument1: arg1
# argument2: arg2
Example 2: bash function arguments
#!/usr/bin/env sh
foo 1 # this will fail because foo has not been declared yet.
foo() {
echo "Parameter #1 is $1"
}
foo 2 # this will work.