22-09-01 Linux shell 脚本if [ -z -n 对变量判断是否为空 binary operator expected too many arguments ,解决:[[ -n ]]

一、脚本里面执行if [ -n `grep "ssid=" /userdata/cfg/wpa_supplicant.conf` ] 会报错binary operator expected 或者 too many arguments。参数中有空格而引起报错这个问题在部分系统执行会出现。这个问题是解决buildroot px30系统机器重启后WIFI不能自动连接的问题。

:/etc/init.d# grep "ssid=" /userdata/cfg/wpa_supplicant.conf
        ssid="xxx-VIP"
        ssid=1
        ssid="xxx-VIPd"

二、解决方法

使用 [[ -n ${ARG} ]] 或 [ -n "${ARG}" ]

三、参考文章

字符串判空有空格报错:binary operator expected_var 字符串里有空格导致报错_xinwendewen的博客-优快云博客

Bash/Shell Programming – Binary Operator Expected | digitalVectorz.. the digital sage.

Linux常用命令7:Linux shell if [ -n ] 正确使用方法_编程设计_IT干货网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值