Unix Shell脚本错误
我对shell脚本非常陌生,我一直在努力使用下面的shell脚本。我将在下面发布我使用的脚本和命令供您参考,请帮助我纠正我犯的错误Unix Shell脚本错误,unix,shell,scripting,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 DEB
#
#
#
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
我认为这是一个“空间”问题:试试看
if [ "$DBG" = "1" ]; then
而不是
if ["$DBG"="1"]; then
尝试将[“$DBG”=“1”]
(以及类似的if语句)更改为:[“$DBG”=“1”]
i、 e.添加一些空间。在添加了一些额外的空间后,它起了作用。谢谢大家。将这些空间放在变量之间是一个脚本规则吗?我想我忽略了这个规则。谢谢你们的时间。这确实是一个空间问题
VAR=VALUE
仅用于shell中的变量声明,而
VAR = VALUE
仅用于变量测试。这很棘手,您只需要习惯它。这是Bash中的语法规则。并非所有脚本/编程语言都需要它,但对于某些脚本/编程语言,它确实需要,Bash就是这样一种语言。谢谢Emil给我的启发。获得了诀窍Raphink。谢谢。