Skip to main content
deleted 1 characters in body
Source Link
slm
  • 380.1k
  • 127
  • 793
  • 897

Hi I have a bash script that intend to run via watch ./script.sh

ItsIt's to debug a cooling problem with my laptop, however the script I wrote isn't working as intended. I'm quite new to bash scripting so II'm sure its something simple.

I have a line in my script that has a nested command substitution but the inner command doesn't appear to work or at least it looklooks like the inner command doesn't know the value of $i. Any help appreciated.

here's the script:

echo "THERMAL ZONE 2:"
echo "Cur Temp: $(cat /sys/class/thermal/thermal_zone2/temp)"

for i in {2..7}
do
echo "cooling_device$i STATE: $(cat /sys/class/thermal/thermal_zone2/cdev$i/cur_state) TRIP POINT TEMP: $(cat /sys/class/thermal/thermal_zone2/trip_point_$(cat /sys/class/thermal/thermal_zone2/cdev$i_trip_point)_temp)"
done

and heres the output:

THERMAL ZONE 2:
Cur Temp: 43000
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device2 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device3 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device4 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device5 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device6 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device7 STATE: 0 TRIP POINT TEMP:

Hi I have a bash script that intend to run via watch ./script.sh

Its to debug a cooling problem with my laptop, however the script I wrote isn't working as intended. I'm quite new to bash scripting so I sure its something simple.

I have line in my script that has a nested command substitution but the inner command doesn't appear to work or at least it look like the inner command doesn't know the value of $i. Any help appreciated.

here's the script:

echo "THERMAL ZONE 2:"
echo "Cur Temp: $(cat /sys/class/thermal/thermal_zone2/temp)"

for i in {2..7}
do
echo "cooling_device$i STATE: $(cat /sys/class/thermal/thermal_zone2/cdev$i/cur_state) TRIP POINT TEMP: $(cat /sys/class/thermal/thermal_zone2/trip_point_$(cat /sys/class/thermal/thermal_zone2/cdev$i_trip_point)_temp)"
done

and heres the output:

THERMAL ZONE 2:
Cur Temp: 43000
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device2 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device3 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device4 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device5 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device6 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device7 STATE: 0 TRIP POINT TEMP:

Hi I have a bash script that intend to run via watch ./script.sh

It's to debug a cooling problem with my laptop, however the script I wrote isn't working as intended. I'm quite new to bash scripting so I'm sure its something simple.

I have a line in my script that has a nested command substitution but the inner command doesn't appear to work or at least it looks like the inner command doesn't know the value of $i. Any help appreciated.

here's the script:

echo "THERMAL ZONE 2:"
echo "Cur Temp: $(cat /sys/class/thermal/thermal_zone2/temp)"

for i in {2..7}
do
echo "cooling_device$i STATE: $(cat /sys/class/thermal/thermal_zone2/cdev$i/cur_state) TRIP POINT TEMP: $(cat /sys/class/thermal/thermal_zone2/trip_point_$(cat /sys/class/thermal/thermal_zone2/cdev$i_trip_point)_temp)"
done

and heres the output:

THERMAL ZONE 2:
Cur Temp: 43000
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device2 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device3 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device4 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device5 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device6 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device7 STATE: 0 TRIP POINT TEMP:
Source Link
squareborg
  • 2.6k
  • 1
  • 21
  • 25

Bash nested command substitution not working

Hi I have a bash script that intend to run via watch ./script.sh

Its to debug a cooling problem with my laptop, however the script I wrote isn't working as intended. I'm quite new to bash scripting so I sure its something simple.

I have line in my script that has a nested command substitution but the inner command doesn't appear to work or at least it look like the inner command doesn't know the value of $i. Any help appreciated.

here's the script:

echo "THERMAL ZONE 2:"
echo "Cur Temp: $(cat /sys/class/thermal/thermal_zone2/temp)"

for i in {2..7}
do
echo "cooling_device$i STATE: $(cat /sys/class/thermal/thermal_zone2/cdev$i/cur_state) TRIP POINT TEMP: $(cat /sys/class/thermal/thermal_zone2/trip_point_$(cat /sys/class/thermal/thermal_zone2/cdev$i_trip_point)_temp)"
done

and heres the output:

THERMAL ZONE 2:
Cur Temp: 43000
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device2 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device3 STATE: 1 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device4 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device5 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device6 STATE: 0 TRIP POINT TEMP: 
cat: /sys/class/thermal/thermal_zone2/cdev: No such file or directory
cat: /sys/class/thermal/thermal_zone2/trip_point__temp: No such file or directory
cooling_device7 STATE: 0 TRIP POINT TEMP: