[root@localhost monitor]# echo "config get *" | redis-cli -a 123456a?
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) "123456a?"
5) "masterauth"
返回結果有Warning:,影響取值
參考鏈接
https://blog.csdn.net/weixin_34253126/article/details/92384670
結果如下
[root@localhost monitor]# echo "config get *" | redis-cli -a 123456a? 2>/dev//null
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) "123456a?"
原因是
warning 這串輸出並不是普通輸出,shell的標准輸出包含兩種,1(標准輸出)2(標准錯誤)我們的命令,即包含1也包含2,2即是我們想要去除的提示。
解決辦法將標准錯誤去除即可,如圖,加了2>/dev/null,將標准錯誤丟棄即可
