bash - 大小写语法错误,但存在语法:语法错误:单词意外(期待“in”)
问题描述
我有一个 bash 脚本,它使用标志变量接受来自 CLI 的输入。这是脚本:
#!/bin/bash
d_flag=''
b_flag=''
c_flag=''
verbose='false'
print_usage() {
printf "invalid flag"
}
while getopts 'd:b:c:v' flag; do
case "${flag}" in
d) d_flag=${OPTARG} ;;
b) b_flag=${OPTARG} ;;
c) c_flag=${OPTARG} ;;
v) verbose='true' ;;
*) print_usage
exit 1 ;;
esac
done
echo $d_flag
echo $b_flag
echo $c_flag
exit 0
这是返回的错误:
user1@debian:/opt/scripts/# sh inputs.sh -d directory -b backupdir -c configdir -v
: not found2: inputs.sh:
: not found7: inputs.sh:
: not found10: inputs.sh: }
: not found11: inputs.sh:
: not found12: inputs.sh:
inputs.sh: 14: inputs.sh: Syntax error: word unexpected (expecting "in")
我无法弄清楚这一点,因为我在 case 语句的语法中有“in”。谁能帮我解决这个问题?
解决方案
推荐阅读
- mpi - 如何使用 MPI_Scatterv 分散行主矩阵的列?
- c++ - 检查pair是否为空或未初始化
- javascript - 成功提交电子邮件表单时如何使用jQuery触发事件
- google-data-studio - 从今天起按 6 个月动态过滤日期
- javascript - 如何获取相对于innerHTML的选择位置
- java - 我的 java 代码无法搜索附近的蓝牙设备
- sql - 手动 byte[] 输入到 SQL Server
- python - 散景垂直条格式问题
- c++ - googlemock 分段错误与 EXPECT_CALL 的简单情况
- aws-sdk - 在 SaaS 订阅后获取 AWS Marketplace 权利