语法错误:“(”意外(期待“fi”)

时间:2014-03-14 01:34:25

标签: shell scripting syntax-error sh

filein="users.csv"

IFS=$'\n'

if [ ! -f "$filein" ]

then

  echo "Cannot find file $filein"

else

  #...

  groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)

  fullnames=(`cut -d: -f 1 "$filein"`)

  userid=(`cut -d: -f 2 "$filein"`)

  usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)


  #...

  for group in ${groups[*]}

  do

    grep -q "^$group" /etc/group ; let x=$?

    if [ $x -eq 1 ]

    then

      groupadd "$group"

    fi

  done


 #...

  x=0

  created=0

  for user in ${usernames[*]}

  do

    useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null

    if [ $? -eq 0 ]

    then

      let created=$created+1

    fi


 #...

    echo "${userid[$x]}" | passwd --stdin "$user" > /dev/null

    #...

    echo "Welcome! Your account has been created.  Your username is $user and temporary 
password is \"$password\" without the quotes." | mail -s "New Account for $user" -b root $user

    x=$x+1

    echo -n "..."

    sleep .25

  done

  sleep .25

  echo " " 

  echo "Complete. $created accounts have been created."

fi

1 个答案:

答案 0 :(得分:0)

我猜测问题是你在没有实际使用命令替换的情况下尝试捕获数组中的命令输出。你想要这样的东西:

groups=( $( cut... ) )

请注意内部集合前面带有$的额外括号。