I have written the following script
#!/bin/bash
echo "Power Details"
fall='/sys/class/power_supply/BAT1'
full=cat $fall/energy_full
echo 'printing here'
echo $full
It is showing the following error:
./power.sh: line 4: /sys/class/power_supply/BAT1/energy_full: Permission denied
The file I am accessing has read permissions to all. Also, while I am simply printing the output of the file, like (editing line 4 of the code):
cat $path/energy_full
It shows no error. Why is this so? How are cat filename
v/s var1 = cat filename
different? What should I do to resolve the issue, without changing read-write-execute permissions of the file I want to access?
NOTE: I am running Kali Linux as a root user
chmod a+x ./power.sh
. Doman chmod
for more information on how privileges work.set -x
in line 2 of the script. This will echo the commands to the console while executing them.