首页 > 解决方案 > 大小写语法错误,但存在语法:语法错误:单词意外(期待“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”。谁能帮我解决这个问题?

标签: bashshellsyntax

解决方案


推荐阅读