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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -