nelsonlombardo

Parameters on bash

Sep 21st, 2020
816
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. TEST1="Default 1"
  4. TEST2="Default 2"
  5. TEST3=""
  6.  
  7. # ./test.sh --test1 "xxxxxx" --test2 "xxxxx" --test3
  8.  
  9. while test $# -gt 0
  10. do
  11.     case "${1}" in
  12.         --test1 | -1) TEST1=${2}; shift;;
  13.         --test2 | -2) TEST2=${2}; shift;;
  14.         --test3 | -3) TEST3="Default3";;
  15.                    *) echo "Wrong parameter: ${1}"; exit 1;;
  16.     esac
  17.     shift
  18. done
  19.  
  20. echo ${TEST1}
  21. echo ${TEST2}
  22. echo ${TEST3}
  23.  
RAW Paste Data