1

It doesn't seem like sed is aware of the $IP variable. How can I get the following to work?

read -p "Please enter the line number with the IP you wish to block from accessing the Internet? " IP

echo $IP

IP_LINE_NUMBER=`nmap -n -sn 192.168.3.0/24 -oG - | awk '/Up$/{print $2}' | sed  '$IPq;d'`

echo $IP_LINE_NUMBER
codeforester
  • 39,467
  • 16
  • 112
  • 140
  • Possible duplicate of [Replace a string in shell script using a variable](https://stackoverflow.com/questions/3306007/replace-a-string-in-shell-script-using-a-variable) – Benjamin W. Jun 10 '17 at 04:25

1 Answers1

0

You have to use double quotes and put {} around IP:

ip_line_number=$(nmap -n -sn 192.168.3.0/24 -oG - | awk '/Up$/{print $2}' | sed  "${IP}q;d")
  • Note: you need command substitution $(...) to get the output into your variable

See also:

codeforester
  • 39,467
  • 16
  • 112
  • 140