linux - Bash warning - argument expected -


the bash script bellow takes mac address variable , finds ip address corresponding mac address.

#!/bin/bash  read address  output="$(nmap -sn -n /ip_address_range/ | grep -b 2 "$address" |  grep -e ^.*[0-9].[0-9].[0-9].[0-9] |  awk '{print substr($0,22)}')"   if [ ${output} = ""];     echo "not found" else     echo "${output}"     arpspoof -i wlan1 -t ${output} /gateway/ fi 

although works fine , expected warning when execute , want find out how fix it. output after enter mac address:

find.sh: 7: [: =: argument expected /ip_address/ **:**:**:**:*:* **:**:**:**:**:** 0806 42: arp reply 192.168.1.1 is-at **:**:**:**:*:* 

there multiple errors. shellcheck finds obvious ones:

first, missing space here:

if [ ${output} = "" ]                    ^--- required 

second, you're missing required quoting:

if [ "${output}" = "" ]      ^-- here -^ 

this should sufficient rid of error you're seeing.

here other problems:

  1. your regex tries match ipv4 address, instead matches 8 character strings every other character digit.

  2. the regex unquoted, accidentally match files in directory , break grep

  3. you run script sh yourscript. works sh scripts. run bash scripts, use bash yourscript.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -