User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Bash script Help please

Mon Mar 09, 2015 9:13 pm

Hi good day, I am trying to write a script i want the script to check for raspberry pi serial if none is the serial echo "test"

For example i have this

Code: Select all

#!/bin/bash
    serial=$(cat /proc/cpuinfo | awk '/Serial/ {print $3}' | tail -c 9)

    while [ $serial != "1111111" ] || [ $serial != "2222222" ]; do
      echo "test"
    done

The problem is for example one of the pi serial is "2222222" but the pi still echos "test"
Those anyone knows the problem? Appreciate the help. :mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Bash script Help please

Mon Mar 09, 2015 9:29 pm

I guess am trying to write a script that says if this serial is not equal to X then try another number if no number matches then echo test. :mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Bash script Help please

Mon Mar 09, 2015 9:33 pm

You probably mean to have logical and (&&) rather than logical or (||). As written the statement must always be true.

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Bash script Help please

Mon Mar 09, 2015 9:40 pm

You need to change

Code: Select all

||
to

Code: Select all

&&
when working with two negative compares.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Bash script Help please

Mon Mar 09, 2015 9:46 pm

DougieLawson wrote:You need to change

Code: Select all

||
to

Code: Select all

&&
when working with two negative compares.
OK thanks for the help that works! "Putting on my green sunglasses instead of mrgreen" . :geek:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

Return to “Beginners”