Question: How to get the network status (online/offline) and attribute it to a variable in shell script?

Answer: 
I'm going to reccomend `ip` again:

```
status=$(ip -o link show eth0 | awk '{print $9}')

```

(The ninth column is the state of the interface)
You say you simply want the online/offline status of an interface, and aren't concerned with speed or link-type.

Try [ethtool](http://linux.about.com/od/commands/l/blcmdl8_ethtool.htm), as root:

```
# ethtool eth0 |grep "Link detected"
  Link detected: yes
# ethtool eth1 |grep "Link detected"
  Link detected: no

```

`ifconfig` can also show you the online/offline status, and this command is usually available to any user on the system. 

```
$ { /sbin/ifconfig eth0 | grep MTU: | grep -w UP >/dev/null 2>&1 ; }; echo $?
0
# This could return some false errors
$ { /sbin/ifconfig eth1 | grep MTU: | grep -w UP >/dev/null 2>&1 ; }; echo $?
1

```