I'm stuck and trying to troubleshoot why the command within the case
statement will not execute within this bash script.
If I copy and paste the command into the command line and hardcode the value it will work. Example: psql -h mycluster-1.us-east-1.redshift.amazonaws.com -U masteruser -d dev -p 5439 -v v1="foo_bar" -f getTableDetails.sql
In the script, I encased the command within parentheses for possible whitespace issues:
#!/usr/local/bin/bash
set -e
set -x
cluster_to_endpoint() {
case "$1" in
c01)
RUNCMD=$(psql -h mycluster-1.us-east-1.redshift.amazonaws.com -U masteruser -d dev -p 5439 -v v1="$NAME" -f getTableDetails.sql)
;;
c02)
RUNCMD=$(psql -h mycluster-2.us-east-1.redshift.amazonaws.com -U masteruser -d dev -p 5439 -v v1="$NAME" -f getTableDetails.sql)
;;
esac
}
while getopts ":c:n:" opt; do
case $opt in
c) cluster="$OPTARG";;
n) name="$OPTARG";;
*) usage
exit 1
;;
esac
done
I am executing the script like so: ./myscript.sh -c c01 -n foo_bar
I've also tried just removing the ()
as well:
c01)
psql -h mycluster-2.us-east-1.redshift.amazonaws.com -U masteruser -d dev -p 5439 -v v1="$NAME" -f getTableDetails.sql;;
It looks like the variables are set.
$ ./myscript.sh -c c01 -n foo_bar
+ getopts :c:n: opt
+ case $opt in
+ cluster=c01
+ getopts :c:n: opt
+ case $opt in
+ name=foo_bar
+ getopts :c:n: opt
So why isn't the command executing? Thanks.
未执行的命令位于函数cluster_to_endpoint
,该函数从未调用过。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.