iwconfig grep 输出作为脚本的一部分

iwconfig grep output as part of a script

#!/bin/bash
MAX=20
while true
do
iwconfig wlan0 txpower $(((RANDOM % $MAX) +1))
set -x #this was not originally included
echo iwconfig wlan0 | grep Tx-Power
done

所以我试图让一个小脚本改变我设备的 tx 功率低于最大值。不久前我的这个工作没有问题,现在已经修改了脚本。从那时起,我更改了主机和虚拟机,这是 运行 打开和不使用 set-x 它只是挂起。每行单独工作,但在脚本中不会将回显输出到屏幕。

当我添加 set -x 时,它会起作用,但也会将 set -x、done 等回显到屏幕上。

知道是什么导致了这种变化以及我该如何解决

一个

你的脚本在无限循环中运行 它还包含以下行:

 echo iwconfig wlan0 | grep Tx-Power

所以你只需回显字符串 "iwconfig wlan0" 然后你尝试在这个脚本中找到 "Tx-Power"。

将此行更改为:

iwconfig wlan0 | grep Tx-Power

所以至少你可以在输出中看到 Tx-Power。