Reputation: 7438
I've tested this command
$ nmap -sP 192.168.1.* | grep 192 | awk '{print $5}'
which produces this output
192.168.1.1
192.168.1.33
192.168.1.34
192.168.1.36
192.168.1.41
And then added it to my .bash_alias file and then sourced it.
# This alias shows IPs on the local network
alias list-ip="nmap -sP 192.168.1.* | grep 192 | awk '{print $5}'"
But then it produces this output
Nmap scan report for 192.168.1.1
Nmap scan report for 192.168.1.33
Nmap scan report for 192.168.1.34
Nmap scan report for 192.168.1.36
Nmap scan report for 192.168.1.41
I've got no clue on what I'm doing whrong. I just want the output to be like when I run it on command-line, and it should be.
Upvotes: 1
Views: 642
Reputation: 45576
You use double quotes, so $5
gets expanded at the time you set the alias. Try
alias list-ip="nmap -sP 192.168.1.* | grep 192 | awk '{print \$5}'"
Note that
alias list-ip='nmap -sP 192.168.1.* | grep 192 | awk "{print $5}"'
will not work because the expansion still takes place, this time when you run the alias.
You can also get rid of the awk
, e.g.:
alias list-ip='nmap -sP 192.168.1.* | grep -o "192[0-9.]*"'
Upvotes: 7