(running Ubuntu 16.04.3) I created small script with tasks I do every time I upgrade/change Ubuntu version. One of the tasks is to write script to file, this is actual written file:
#!/bin/bash
if [ "$1" == "eno1" ]; then
case "$2" in
up) nmcli radio wifi off
notify-send "cable network detected, turning WIFI off" -u low -t 10;;
down) nmcli radio wifi on
notify-send "cable network unplugged, turning WIFI on" -u low -t 10;;
esac
fi
And this is how I write it from another script:
MY_FILE="/etc/NetworkManager/dispatcher.d/99-wlan"
ni="$(nmcli dev status | grep ethernet | awk '{ print $1 }')"
echo -e '#!/bin/bash\n\nif [ "$1" == "'"$ni"'" ]; then\n case "$2" in\n'\
' up) nmcli radio wifi off\n notify-send "cable network detected, turning WIFI off" --urgency critical --expire-time 6;;\n'\
' down) nmcli radio wifi on\n notify-send "cable network unplugged, turning WIFI on" --urgency critical --expire-time 6;;\n'\
' esac\nfi' | sudo tee -a "$MY_FILE" > /dev/null
sudo chmod +x "$MY_FILE"
My question is, if syntax I'm using is correct. When I check it with shellcheck utility, it complaints about first line:
echo -e '#!/bin/bash\n\nif [ "$1" == "'"$ni"'" ]; then\n case "$2" in\n'\
^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
can I ignore this warnings or is there a better how to write it ? Keep in mind I'm using variable $ni when I'm writing to file.
$1
is something other thaneno1
? \$\endgroup\$