I have a following requirement of running the azure cli commands in a bash script file, for which i have created two script files as below
to set the environment (environment.sh)
#!/bin/sh echo "setting environment" export az_resource_group="test-group" echo "resource group is $az_resource_group" export az_source_server="test-server" echo "source_server is $az_source_server" export az_recovery_server="test-recovery-server" echo "recovery-server is$az_recovery_server" export az_restore_time="2020-07-27T12:52:21.000Z" echo "restore point in time is $az_restore_time"
the actual script file to run azure cli commands (azurecommands.sh)
#!/bin/sh resource_group=$az_resource_group recovery_server=$az_recovery_server source_server=$az_source_server restore_time=$az_restore_time echo "restoring postgresql database" echo "az postgres server restore -g $resource_group --restore-point-in-time $restore_time -s $source_server -n $recovery_server"
the above az command works properly when run individually or using arguments in bash, but if i use environment variables the command itself does not form correctly. so i decided to print it so that i can verify what is command that is being formed.
To my surprise the output is -n test-recovery-server 2020-07-27T12:52:21.000Z
while my expected output is az postgres server restore -g test-group --restore-point-in-time -s test-server -n test-recovery-server
.
I'm also making sure to run environment.sh file as follows:
source environment.sh
How can echo not print the correct command? is there something with the way i use environmental variables? if so please suggest me some other approach, because these commands need to be automated.