[英]How to get the wlan number in the linux system using BASH script
I want to write a script to enable the wireless driver. 我想编写一个脚本来启用无线驱动程序。
If I input iwconfig
in the terminal, it will give me the following output: 如果我在终端中输入
iwconfig
,它将得到以下输出:
lo no wireless extensions.
eth0 no wireless extensions.
wlan3 IEEE 802.11bgn ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=0 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
What I want to do next is to input: 我接下来要做的就是输入:
ifconfig wlan3 up
Is there a way to extract the number 3
from the first output and make those into a bash script? 有没有办法从第一个输出中提取数字
3
并将其制作为bash脚本?
iwconfig
prints only wireless interfaces to stdout
, other output is in fact stderr
. iwconfig
仅将无线接口输出到stdout
,其他输出实际上是stderr
。 Therefore the following command will work regardless of interface name. 因此,无论接口名称如何,以下命令都将起作用。
$ iwconfig 2>/dev/null | grep -o "^\w*"
if you just want want ifconfig wlan3 up
, then you don't need to isolate the 3. 如果只想将
ifconfig wlan3 up
,则无需隔离3。
you can get wlan3 with just 你可以用
$ iwconfig | grep -o "^wlan[0-9]\+"
wlan3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.