0

I have the following scenario

Step1

 local output=$(sshpass -p ${PSSWD} ssh -tt -oStrictHostKeyChecking=no root@$IP "$(< vXU-script.sh)")

step 2

mapfile -t RIU_ARRAY < <(echo "$output" | grep "RIU-[1-4] ----> ")

the above line will grep the following line

RIU-1 ----> AB019030015 ----> 223a:c03a:261:1141:0:50:c389:22ff

step 3 (loop RIU_ARRAY)

ip=$(echo "${item}" | awk -F" " '{print $5}')

The above line will get the IP part 223a:c03a:261:1141:0:50:c389:22ff

      if [ "${ip}" == "223a:c03a:261:1141:0:50:c389:22ff" ]; then
          echo "#### Same"
      else
        echo "#### Different"
      fi

The above line is always False and the following line is printed #### Different

I expect it to be the same. Is this because of the semi-colon or CLI console greped character encoding issues?

electricalbah
  • 2,227
  • 2
  • 22
  • 36

1 Answers1

0

Most likely, the 'sshpass | ssh -tt' will result in line ending with '\r\n'.

Considering 2 options - Filtering with 'tr' will (almost) always work. But the '-tt' seems cleaner.

  1. The '-tt' cause terminal allocation, which is injecting '\r'. If possible, try running without it.
  2. If this is not an option, pipe output into "tr -d '\r'"
 local output=$(sshpass -p ${PSSWD} ssh -tt -oStrictHostKeyChecking=no root@$IP "$(< vXU-script.sh)" | tr -d '\r')
dash-o
  • 13,723
  • 1
  • 10
  • 37