7 Replies Latest reply on Mar 5, 2015 9:00 AM by JPMontero_Intel

    How to fix error for script code in sh shell for edison.(script code works well in Bash shell).

    Taylor.Xie

      Hello,

       

      I have copied a script file to Edison, but it didn't work and has some errors....

      BTW: Before that, this script file works very well in Raspberry Pi, The only difference is that Edison used Sh shell , Raspberry Pi used Bash shell.



      Edison version: edison-image-rel1-maint-rel1-ww42-14


      this script code:

      #!/bin/sh -x

      # iBeacon Scan by Radius Networks

      echo $1

      if [[ "$1" == "parse" ]]; then

        echo "----parse got"

        packet=""

        capturing=""

        count=0

        callwebcount=0

        while read line

        do

          echo "----in while"

          count=99

          #$[count + 1]

          echo "----done count plus"

          if [ "$capturing" ]; then

            echo "----in capturing"

            if [[ $line ==~ ^[0-9a-fA-F]{2}\ [0-9a-fA-F] ]]; then

              echo "----in line"

              packet="$packet $line"

            else

              echo "----in noline"

              if [[ $packet ==~ ^04\ 3E\ 2A\ 02\ 01\ .{26}\ 02\ 01\ .{14}\ 02\ 15 ]]; then

                RAWRESULT=`echo $packet | sed -e 's/^\(.\{134\}\).*$/\1/'`

                if [[ $2 == "-b" ]]; then

                  callwebcount=$[callwebcount + 1]

                  echo "-------start----"

                  echo "$RAWRESULT"

                  echo "-------end------"

                  curl --get --data-urlencode "raw=$RAWRESULT" "http://192.168.1.100:8090/Identification.aspx"

                  echo "call web count: $callwebcount"

                else

                  echo "UUID: $UUID MAJOR: $MAJOR MINOR: $MINOR POWER: $POWER RSSI: $RSSI MAC: $MAC"

                fi

              fi

              capturing=""

              packet=""

            fi

          fi

          if [ ! "$capturing" ]; then

            tempStr = `echo $line | sed -n '/^\>/p'`

            if [ $line ]; then

              echo "----in line2"

              packet=`echo $line | sed 's/^>.\(.*$\)/\1/'`

              echo "----in done line2"

              capturing=1

            fi

          fi

        done

      else

        hcitool lescan --duplicates 1>/dev/null

        echo "lescan in backgroud..."

        sleep 3

        if [ "$(pidof hcitool)" ]; then

          echo "hcidumping raw..."

          hcidump --raw | $0 "parse" $1

          #echo "hcidumping raw done"

          #./$0 "parse" $1 < tmpp

          #rm tmpp   

        fi

      fi

       

      Result:

      root@Edison:~# ./IBeaconSensor.sh

      + echo

       

      + [[  == parse ]]

      + echo lescan in backgroud...

      + lescan in backgroud...

      + hcitoolsleep lescan 3 --duplicates

       

      + pidof hcitool

      + [ 474 ]

      + echo hcidumping raw...

      hcidumping raw...

      + hcidump --raw

      + ./IBeaconSensor.sh parse

      + echo parse

      parse

      + [[ parse == parse ]]

      + echo ----parse got

      ----parse got

      + packet=

      + capturing=

      + count=0

      + callwebcount=0

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ HCI sniffer - Bluetooth packet analyzer ver 5.18 =~ ^> ]]

      sh: sniffer: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ device: hci0 snap_len: 1500 filter: 0xffffffff =~ ^> ]]

      sh: hci0: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ > 04 3E 2A 02 01 00 00 8B C5 9F 9D 66 7C 1E 02 01 1A 1A FF 4C =~ ^> ]]

      sh: 04: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ 00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 D0 F5 A7 10 96 E0 00 =~ ^> ]]

      sh: 02: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ 0A 00 08 C5 F1 =~ ^> ]]

      sh: 00: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ > 04 3E 2A 02 01 00 00 8B C5 9F 9D 66 7C 1E 02 01 1A 1A FF 4C =~ ^> ]]

      sh: 04: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ 00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 D0 F5 A7 10 96 E0 00 =~ ^> ]]

      sh: 02: unknown operand

      + read line

      + echo ----in while

      ----in while

      + count=99

      + echo ----done count plus

      ----done count plus

      + [  ]

      + [ !  ]

      + echo test

      test

      + [[ 0A 00 08 C5 E0 =~ ^> ]]

      sh: 00: unknown operand

      + read l^C

      root@Edison:~#