Mic*_*ant -2 shell bash shell-script arithmetic variable
我想输入一个数字,然后加税并减去折扣。
我在尝试:
#!/bin/sh
...
final_amount = $(echo "$purchase_amount+($purchase_amount * $tax)-($purchase_amount * $discount)" |bc -l)
...
Run Code Online (Sandbox Code Playgroud)
但我得到:
$ . 3_purchase_amounts.sh
...
final_amount: command not found
...
Run Code Online (Sandbox Code Playgroud)
不要final_amount在行中的“=”字符周围放置空格:shell 中的变量赋值不支持这样的空格,因为这会与诸如command_name = arg2. 如您所见,shell 尝试执行final_amount命令,但出现错误:
final_amount: command not found
Run Code Online (Sandbox Code Playgroud)