Bash function example and trics
Validata correct number of arguments if [ "$#" -ne 2 ]; then echo "Illegal number of parameters ($#, should be 2)" exit 1 fi $# returns number of parameters passed to script. If it’s less then 2, script ends with error. Check if environment variable is set if [ -z "$CLEANING_JOB" ] then echo "Environmental variable [CLEANING_JOB] does not exist." exit 1 fi Bash function example set_dir_structure() { YEAR=$(date +"%Y" "$@") MONTH=$(date +"%m" "$@") DAY=$(date +"%d" "$@") HOUR=$(date +"%H" "$@") retval="$YEAR/$MONTH/$DAY/$HOUR" } This function can be executed with or without parameter to get proper dir structure related with date and time....