-bash:警告:命令替换:忽略输入中的空字节
我总是很紧张-bash:警告:命令替换:忽略输入中的空字节,bash,variables,calculation,Bash,Variables,Calculation,我总是很紧张 -bash: warning: command substitution: ignored null byte in input 执行以下代码时出现警告: BW=`bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"` 但该代码不起作用: BW=tr -d '\0' < `bc <<< &q
-bash: warning: command substitution: ignored null byte in input
执行以下代码时出现警告:
BW=`bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`
但该代码不起作用:
BW=tr -d '\0' < `bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`
得到警告是因为
grep-z
在结果末尾输出一个零字节,而shell无法处理这个问题。简单的解决方案是放弃该选项,或者找到一种方法用shell实际能够处理的东西替换它。实际上,它在这里似乎没有任何用处。。。但可能会丢失并使用现代命令替换语法,而不是过时的backticks,以及
BW=$(请看这是否有用-请查找上面的更新。
BW=tr -d '\0' < `bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`
-bash: warning: command substitution: ignored null byte in input
-bash: `bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`: No such file or directory
BW=`bc <<< "$(cat $TMP | grep -Pzo '(?<="outgoing_traffic": )(.*)(?=,)')/1024^3"`
echo $BW
-bash: warning: command substitution: ignored null byte in input
4
bash$ echo hello | tr '\n' '\0' | xxd
00000000: 6865 6c6c 6f00 hello.