小编Dar*_*ron的帖子

无法在 Bash 中将输出捕获到变量中

有问题redis-cli。我想redis通过 BASH检查连接是否被拒绝(服务器关闭)。

简单测试

#!/bin/bash
test=$(redis-cli exit) #exit out of the "not connected console"
if [[ -z $test ]] ; then
    echo "I'm empty :("
fi
Run Code Online (Sandbox Code Playgroud)

我希望Could not connect to Redis at 127.0.0.1:6379: Connection refused存储在 $test 中,但此文本会输出到控制台。

我不确定发生了什么。谁有想法?

(Ubuntu 14.04.1)

command-line bash output

15
推荐指数
1
解决办法
9692
查看次数

标签 统计

bash ×1

command-line ×1

output ×1