Associative arrays in Shell scripts

Another option, if portability is not your main concern, is to use associative arrays that are built in to the shell. This should work in bash 4.0 (available now on most major distros, though not on OS X unless you install it yourself), ksh, and zsh: declare -A newmap newmap[name]=”Irfan Zulfiqar” newmap[designation]=SSE newmap[company]=”My Own Company” … Read more

How to get the primary IP address of the local machine on Linux and OS X? [closed]

Use grep to filter IP address from ifconfig: ifconfig | grep -Eo ‘inet (addr:)?([0-9]*\.){3}[0-9]*’ | grep -Eo ‘([0-9]*\.){3}[0-9]*’ | grep -v ‘127.0.0.1’ Or with sed: ifconfig | sed -En ‘s/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p’ If you are only interested in certain interfaces, wlan0, eth0, etc. then: ifconfig wlan0 | … You can alias the command in your .bashrc … Read more