unix - shell 脚本错误

标签 unix shell scripting

我是 shell 脚本的新手,我一直在努力使用以下 shell 脚本。我发布了我在下面使用的脚本和命令供您考虑,请帮助我解决我犯的错误。

#
#
#

DBG=0
RLS=0
ALL=0
CLN=0

print_help_uu()
{
        echo "Usage: $0 -D -R -A -C "; 
        echo "Where -C clean the debug project builds";
        echo "      -D to build in DEBUG config";
        echo "      -R to build in RELEASE config";
        echo "      -A to build in both configs";
        return
}

#
# Main procedure start here
#
# Check for sufficent args
#

if [ $# -eq 0 ] ; then
        print_help_uu
        exit 1
fi    

#
# Function to clean the project
#
clean()
{
        if ["$DBG"="1"]; then
            echo "Cleaning debug"

            if ["$RLS"="1"]; then
                echo "cleaning release + debug"
            else
                echo "This is bad"
            fi
        fi

        if ["$RLS"="1"]; then 
            echo "Cleaning release "
        fi
        return
}


while getopts "DRAC" opt
do
        case "$opt" in
                D) DBG=1;;
                R) RLS=1;;
                A) DBG=1;RLS=1;;
                C) CLN=1;;
                \?) print_help_uu; exit 1;; 
        esac
        clean
done   

我发布了我用来运行它的命令以及我在使用这些命令时遇到的错误。

----------
./BuildProject.sh -D
./BuildProject.sh: line 36: [1=1]: command not found
./BuildProject.sh: line 46: [0=1]: command not found

-----------
sh BuildProject.sh -D
BuildProject.sh: 63: [1=1]: not found
BuildProject.sh: 63: [0=1]: not found

-----------
sh ./BuildProject.sh -D
./BuildProject.sh: 63: [1=1]: not found
./BuildProject.sh: 63: [0=1]: not found

我尝试了很多方法来解决它,并在此处发布之前进行了很多谷歌搜索。但是我所有的尝试都是徒劳的。请告诉我哪里做错了,因为我是 shell 脚本的新手。

提前致谢。

最佳答案

[ 是一个命令,但您正在尝试调用命令 [1=1]。添加一些空格:

if [ "$DBG" = "1" ]; then

关于unix - shell 脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1968827/

相关文章:

scripting - [ powershell 中的字符

linux - 如何准确复制文件夹

linux - 使用 Awk 将服务器名称从列表传递到 nslookup

linux - 如何从 Linux 中的数据文件中删除第一列(实际上是行名称)?

shell - 在 HDFS 中查找文件的行数以与 QC 文件中的行数进行比较

scripting - 更改MSI中 Action 序列记录的脚本

file - 移动名称中有空格的文件

有人可以解释 Solaris 中 'dirent' 结构的定义吗?

python - 使用 python 在命令行上键入时完成

linux - 在 ssh 进入 DC 的时钟服务器后,如何在我的脚本中触发脚本?