shell - Getopts with curl bash -


i have got question how connect getopts curl method in 1 function ? newbie in bash scripting. add function below:

    addproject() {          addproject_usage() { echo "addproject: [-p <arg>]" 1>&2; exit; }         read optarg         local optind o p         local optarg         while getopts ":p:" o;             case "${o}" in                 p)                     p="${optarg}"                    ;;                 *)                     addproject_usage                 ;;             esac         done         shift $((optind-1))   curl -h "content-type:application/json" http://adress.com/api/v3/projects?private_token=$token -d "{ \"name\": \"$p\" }" }  addproject -p  addproject 

thank advice , ! dont know if right don't think .

m.

i think script simplified few:

#!/bin/bash  #  addproject_usage() { echo "addproject: [-p <arg>]" 1>&2; exit; }  addproject() {          local p         p="mypdefault"          while getopts ":p:" o;             case "${o}" in                 p)                     p="${optarg}"                    ;;                 *)                     addproject_usage                 ;;             esac         done         shift $((optind-1))   curl -h "content-type:application/json" http://adress.com/api/v3/projects?private_token=$token -d "{ \"name\": \"$p\" }" }  addproject -p foo  addproject 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -