Command Substitution],
在bash中命令替换的格式是 $(command option) 或者 `command option`, 比如sdcard_mounted="$(mount | grep /dev/mmcblk1p2 | awk '{print $3}')" mount 命令执行的结果被赋给sdcard_mounted变量, nowDate=$(date +"%Y-%m-%d %H:%M:%S") date命令执行的结果被赋给nowDate变量.
下面函数展示了命令替换, {}扩展和变量替换
ucd90160_test()
{
local vout
local iout
ucd90160_fail=0;
echo "************************Total 13 Rail output available*************************"
for channel in {1..9}
do
vout=$(more /sys/bus/i2c/devices/1-0068/hwmon/hwmon1/in${channel}_input)
if [ "$vout" -gt "0" ]
then
echo -e "*\t\tRail${channel} value is:\t\t\t\t\t${vout}\t\t*"
else
ucd90160_fail=1
fidone;
for channel in {10..13}
do
vout=$(more /sys/bus/i2c/devices/1-0068/hwmon/hwmon1/in${channel}_input)
if [ "$vout" -gt "0" ]
then
echo -e "*\t\tRail${channel} value is:\t\t\t\t${vout}\t\t*"
else
ucd90160_fail=1
fidone;
echo "*******************************************************************************"if [ "${ucd90160_fail}" -eq "0" ];then
echo -e "\n${GREEN}****UCD90160 (PMbus protocol) Test Passed***${NC}"
else
echo -e "\n${RED}****UCD90160 (PMbus protocol) Test Failed***${NC}"
fi
}