小编Ber*_*nox的帖子

-bash:警告:命令替换:忽略输入中的空字节

我总是得到

-bash: warning: command substitution: ignored null byte in input
Run Code Online (Sandbox Code Playgroud)

执行以下代码时出现警告:

BW=`bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`
Run Code Online (Sandbox Code Playgroud)

如果结果不为零,也会出现该警告。

我怎样才能避免这种情况?

当它确实为 0 时,我怎样才能跳过该错误?

更新我尝试了下面提供的解决方案:

tr -d '\0' 
Run Code Online (Sandbox Code Playgroud)

但该代码不起作用:

BW=tr -d '\0'  < `bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`
Run Code Online (Sandbox Code Playgroud)

输出:

-bash: warning: command substitution: ignored null byte in input
-bash: `bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`: No such file or directory
Run Code Online (Sandbox Code Playgroud)

有趣的侧面事实,它不是 0

BW=`bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"` …
Run Code Online (Sandbox Code Playgroud)

variables bash calculation

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

标签 统计

bash ×1

calculation ×1

variables ×1