Skip to content
Advertisement

A confusion about the alias area of bashrc file

I want write my own alias called oepnserver. The functions of the oepnserver are:

  • show my ip address
  • use python module to start a server on current folder.

The detailed code is listed below:

alias openserver="ifconfig wlan0 |grep inet |awk '{print $2}' && python3 -m http.server 54188"

When I type oepnserver, my terminal only shows:

        inet 172.34.162.200  netmask 255.255.224.0  broadcast 172.34.191.255
Serving HTTP on 0.0.0.0 port 54188 (http://0.0.0.0:54188/) ...

However, my expectation was

172.34.162.200
Serving HTTP on 0.0.0.0 port 54188 (http://0.0.0.0:54188/) ...

I also try to use the ifconfig wlan0 |grep inet |awk '{print $2}' along, and I get the correct output.

Should I use another way to combine these two commands instead of &&? Or I just made some typo?

Advertisement

Answer

Based on your shown code I am trying to optimize it which could be done by single awk.

ifconfig wlan0 | awk '/inet /{print $2}' && your python code

Also IMHO you should try to make this as a function rather than alias.

Advertisement