LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   basic bash script (https://www.linuxquestions.org/questions/linux-newbie-8/basic-bash-script-4175543732/)

vincix 05-27-2015 06:44 AM

basic bash script
 
Code:

PREFIX=192.168.1
OCTET=1
while [ $OCTET -lt "255" ]; do
    echo -en "Pinging ${PREFIX}.${OCTET}..."
    ping -c1 -w1 ${PREFIX}.${OCTET} > /dev/null 2>&1
    if [ "$?" -eq "0" ]; then
      echo "OK"
    else
      echo "Failed"
    fi
    let OCTET=$OCTET+1
done

My question is, in the penultimate line, why is it OCTET, and not $OCTET, with a dollar before it, meaning, the variable?

What if it were written:
Code:

let $OCTET=$OCTET+1
Like in C++ (I think) or Python or whatever?

veerain 05-27-2015 06:48 AM

Read man page of bash.

In shell every variable is referenced without '$'. Only if you want the value of a variable '$' is used.

And it is designed so.

vincix 05-27-2015 07:07 AM

Thanks


All times are GMT -5. The time now is 09:22 AM.