I am trying to take a string of options fed to a bash script and assign them to variables with case. I believe case is conditional. Is there a way to have case loop through the options and assign variables? I am using some once and looping through others. The print loop doesn't work after the case statement.
example:
run script: ./ping_ds_replication_setup --bind_dn nate --bind_password password --slave_ds_servers server1 server2 server-name.troweprice.io --master_ds_server server3 --admin_uid nate --admin_password password
output currently: ping_bind_dn: nate bind password: password secondary servers: server1 secondary servers: server2 secondary servers: server-name.troweprice.io master ds server: server3 admin_uid: nate admin_password: password
script:
while [ -n 1 ]; do
case "$1" in
--bind_dn)
ping_bind_dn=$2
printf "ping_bind_dn: $ping_bind_dn\n"
shift
;;
--bind_password)
bind_password=$2
printf "bind password: $bind_password\n"
shift
;;
--admin_uid)
admin_uid=$2
printf "admin_uid: $admin_uid\n"
shift
;;
--admin_password)
admin_password=$2
printf "admin_password: $admin_password\n"
shift
;;
--master_ds_server)
master_ds_server=$2
printf "master ds server: $master_ds_server\n"
shift
;;
--slave_ds_servers)
slave_raw_input=( $@ )
slave_switch_removed=${slave_raw_input[@]:1}
regex2=$(grep -Po '.*?(?=--)' <<< ${slave_switch_removed[@]})
secondary_ds_server=($(echo "${regex2}"|head -n 1))
for secondary_server in "${secondary_ds_server[@]}"; do
printf "secondary servers: $secondary_server \n"
done
shift
esac
shift
done
for secondary_server in "${secondary_ds_server[@]}"; do
printf "secondary servers outside case: $secondary_server \n"
done