红联Linux门户
Linux帮助

求助:shell这个错误是怎么回事

发布时间:2012-03-17 01:29:52来源:红联作者:hong900116
[code]#!/bin/bash

MINPARAMS=10
echo
echo "the name of this script is \"$0\"."
echo "the name of this script is \"basename $0\"."
echo "============================================"
echo
if[-n "$1"];then
echo "parameter #1 is $1"
fi
if[-n "$2"];then
echo "parameter #2 is $2"
fi
echo "============================================"
echo "all the parameter are $*"
echo "the number of parameter is $#"
echo
[/code]运行结果:
the name of this script is "./parameter.sh".
the name of this script is "basename ./parameter.sh".
============================================

./parameter.sh: line 9: syntax error near unexpected token `then'
./parameter.sh: line 9: `if[-n "$1"];then'
文章评论

共有 3 条评论

  1. yanyongkg 于 2012-03-17 13:28:50发表:

    if [ 之间也要空格

  2. 于 2012-03-17 13:28:00发表:

    if [ 之间也得空格

  3. 相思爱文 于 2012-03-17 11:58:25发表:

    [ 和 ] 两边要留有空格才行

    if [ -n "$1" ] ;then