Issue
I am trying to write shell script to read the value from /sys/class/net/eth0/carrier but it's giving me the "permission denied" exception . The command I am trying to write in the shell script is
sudo echo $(/sys/class/net/eth0/carrier)
What I also noticed is that I am getting the same exception when I logged in as root and tried this:
echo $(/sys/class/net/eth0/carrier)
Any help in trying to read the value executing the shell script is greatly appreciated.
Solution
The syntax you have tries to execute that file. If you want to contents of the file in a variable, do something like this (probably bash-only syntax):
foo=$(</sys/class/net/eth0/carrier)
Or (portable)
foo=$(cat /sys/class/net/eth0/carrier)
If you just want to print it out to stdout
:
cat /sys/class/net/eth0/carrier
Answered By - Mat