Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何回显数学表达式的结果并将其保存到Bash中的变量_Bash_Shell_Scripting - Fatal编程技术网

如何回显数学表达式的结果并将其保存到Bash中的变量

如何回显数学表达式的结果并将其保存到Bash中的变量,bash,shell,scripting,Bash,Shell,Scripting,我需要将下面的公式回传到命令行,并保存到变量中。到目前为止,我也没有做到这一点 5^0.16 我已经试过了 echo 'e(l(5)*.16)' | bc -l 以及 echo 'e(l(5)*.16)' | bc -l | read wcEXP 怎么样 wcExp=$(echo'e(l(5)*.16)| bc-l) 回显“$wcExp” 如果使用Bash,可以使用tee将输出复制到标准错误: res=$(bc -l <<< 'e(l(5)*.16)' | tee /dev

我需要将下面的公式回传到命令行,并保存到变量中。到目前为止,我也没有做到这一点

5^0.16

我已经试过了

echo 'e(l(5)*.16)' | bc -l
以及

echo 'e(l(5)*.16)' | bc -l | read wcEXP
怎么样

wcExp=$(echo'e(l(5)*.16)| bc-l)
回显“$wcExp”

如果使用Bash,可以使用
tee
将输出复制到标准错误:

res=$(bc -l <<< 'e(l(5)*.16)' | tee /dev/stderr)

我将方程存储在一个变量中,将其导入
bc-l
并存储结果(
result=$(echo“${equation}”| bc-l)
)。这会给你方程和结果的变量。
$ res=$(bc -l <<< 'e(l(5)*.16)' | tee /dev/stderr)
1.29370483333398597850
$ declare -p res
declare -- res="1.29370483333398597850"