I have the following script to detect when my network comes back on after restarting my router:
#!/bin/bash
pingCommand="ping 192.168.1.1 -c 3 &>/dev/null"
while [[ ! $($pingCommand) ]]; do
sleep 3s;
done
However, when run in the terminal, it prints:
ping: unknown host &>/dev/null
I ran the script with the -x
option (to enable debugging) and found that
ping 192.168.1.1 -c 3 &>/dev/null
was being executed in the subshell as
ping 192.168.1.1 -c 3 '&>/dev/null'
How do I change my command substitution call so that bash does not put single quotes around the output redirection?