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
Post a Comment