我总是得到
-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)