shell脚本取余计算
时间: 2023-10-17 21:31:53 浏览: 177
在Shell脚本中,可以通过使用求余运算符 "%" 来进行取余计算。根据引用[3]中的示例代码,可以将需要计算取余的两个数值分别赋值给变量,然后使用求余运算符进行计算。例如,如果想计算4除以3的余数,可以使用如下代码:
```
num=$((4%3))
echo $num
```
运行这段代码,将输出结果为1,即4除以3的余数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Shell脚本编程100例](https://download.csdn.net/download/u013561552/74703087)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [shell脚本中的运算](https://blog.csdn.net/weixin_45436958/article/details/100065454)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [shell算术运算(加减乘除求余)](https://blog.csdn.net/qq_41419761/article/details/84033620)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文