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:
your regex tries match ipv4 address, instead matches 8 character strings every other character digit.
the regex unquoted, accidentally match files in directory , break
grep
you run script
sh yourscript
. workssh
scripts. runbash
scripts, usebash yourscript
.
Comments
Post a Comment