bash - bash:用源加载的变量不能用于算术运算
问题描述
我有一个带有变量的简单文件(test.ini):
v2="1"
在脚本中,我尝试对加载的变量进行算术运算,但总是得到一个“无效的算术运算符”。
脚本:
#!/bin/bash
# Works as it should.
v1="1"
echo "$((v1+1))"
# Throws ")syntax error: invalid arithmetic operator (error token is ".
source "test.ini"
echo "$((v2+1))"
我在 Centos 7 和 bash 4.2.46(2)-release 上运行它。
我搜索了谷歌,找不到类似的东西。非常感谢任何帮助。
沃尔德马尔
解决方案
推荐阅读
- mysql - 无法使用正确的命令删除记录
- python - 在 Python 2.7 中,如何在没有 pep8 警告的情况下使用 try & except 检查所有异常?
- python-3.x - django 中的 NoReverseMatch(带模板的相对 url)
- webpack - NestJS 热模块替换:无效的选项对象
- reactjs - AntD DirectoryTree的节点按字母顺序排序
- r - 处理二项式数据时,如何将女性和男性视为二元变量?
- javascript - 在 HTML 中的画布上使用贝塞尔曲线获得 S 形
- amazon-web-services - 尝试将代码推送到 AWS CodeCommitt 存储库时如何解决此错误?
- python - 如何修复 jupyter notebook 中的错误:图像数据无法转换为浮点数?
- c++ - 在 C++ 中解压缩可选项是否有不那么冗长的习语?