awk - How to create an alias correctly -
i've tested command
$ nmap -sp 192.168.1.* | grep 192 | awk '{print $5}'
which produces output
192.168.1.1 192.168.1.33 192.168.1.34 192.168.1.36 192.168.1.41
and added .bash_alias file , sourced it.
# alias shows ips on local network alias list-ip="nmap -sp 192.168.1.* | grep 192 | awk '{print $5}'"
but produces output
nmap scan report 192.168.1.1 nmap scan report 192.168.1.33 nmap scan report 192.168.1.34 nmap scan report 192.168.1.36 nmap scan report 192.168.1.41
i've got no clue on i'm doing whrong. want output when run on command-line, , should be.
you use double quotes, $5
gets expanded @ time set alias. try
alias list-ip="nmap -sp 192.168.1.* | grep 192 | awk '{print \$5}'"
note
alias list-ip='nmap -sp 192.168.1.* | grep 192 | awk "{print $5}"'
will not work because expansion still takes place, time when run alias.
you can rid of awk
, e.g.:
alias list-ip='nmap -sp 192.168.1.* | grep -o "192[0-9.]*"'
Comments
Post a Comment