0

How can I assign a command to variable in a bash script? My script works like a charm when I start it

while true
        do
        echo "Building Local Tunnel"
        /opt/nodejs/lib/node_modules/localtunnel/bin/client --subdomain celero --port 8001 > /var/www/html/status
        sleep 2
        done

The problem is that I would like to know when my domain will be changed. So I can react on this.

Im trying to setup tunnel connection and assign the output into a variable. If the domain is changed I would like to save a new address to a file. My code doesn't work now. Could someone help me please?

#!/bin/bash
#sleep 6
dir=/home/pi/address.txt
while true
        do
        /opt/nodejs/lib/node_modules/localtunnel/bin/client --subdomain celero --port 8001 > $domain
        echo "${domain}"
        if [ "${domain}" != "${temp}" ]; then
                "${domain}" > "${dir}"
        fi
        $temp = $domain
        sleep 2
        done
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Anna K
  • 1,666
  • 4
  • 23
  • 47
  • 1
    BTW, running your code through http://shellcheck.net/ will identify some other issues (f/e, the assignment should be `temp=$domain` -- no spaces around the `=`, no `$` on the left). – Charles Duffy Apr 29 '18 at 17:08
  • Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Apr 29 '18 at 18:42

0 Answers0