我上面有一些代码,它是一个pdf文档,无论我在哪里尝试发布它,缩进都很糟糕,我想将其设置为正确的格式以进行调试。这是我的代码:
#!/bin/bash
# to measure average power consumed in 30sec with 1sec sampling interval
duration
=
30
interval
=
1
RAILS
=(
"
VDD_IN /sys/bus/i2c/drivers/ina3221x/0-
0041/iio:device1/in_power0_input"
"VDD_SYS_GPU /sys/bus/i2c/drivers/ina3221x/0-
0040/iio:device0/in_power0_input"
"VDD_SYS_CPU /sys/bus/i2c/drivers/ina3221x/0-
0041/iio:device1/in_power1_input"
"VDD_SYS_SOC /sys/bus/i2c/drivers/ina3221x/0-
0040/iio:device0/in_power1_input"
"VDD_SYS_DDR /sys/bus/i2c/drivers/ina3221x/0-
0041/iio:device1/in_power2_input"
"VDD_4V0_WIFI /sys/bus/i2c/drivers/ina3221x/0-
0040/iio:device0/in_power2_input"
)
for
((
i
=
0
;
i
<
${#RAILS[@]}
;
i++
));
do
Optimizin
g Jetson TX2 for Power and Performance
Jetson TX2
TDG
-08413-
001_v1.0
| 28
read
name
[
$i]
node
[
$i]
pwr_sum
[
$i]
pwr_count
[
$i]
<<<$(echo
"${RAILS[$i]} 0 0")
done
end_time
=$(($(date '+%s')
+
duration
))
while
[
$(date '+%s')
-
le
$end_time
];
do
for
((
i
=
0
;
i
<
${#RAILS[@]}
;
i++
));
do
pwr_sum
[
$i]=$((
${pwr_sum[$i]}
+
$(cat ${node[$i]})))
&&
pwr_count
[
$i]=$((
${pwr_count[$i]}
+
1
))
done
sleep
$interval
done
echo
"RAIL,POWER_AVG"
for
((
i
=
0
;
i
<
${#RAILS[@]}
;
i++
));
do
pwr_avg
=$((
${pwr_sum[$i]}
/
${pwr_count[$i]}
))
echo
"${name[$i]},$pwr_avg"
done
我是手动完成的,但我想知道是否可以自动完成。
答案1
你使用什么IDE?在 VIM 中,gg=G
效果相当好。如果您使用 Atom,请参阅以下内容:https://atom.io/packages/format-shell。
答案2
格式外壳使用shfmt
(https://github.com/mvdan/sh)在引擎盖下。该工具可以插入 CI 或作为pre-commit
钩子