一个脚本

一个脚本

$cat ex1
#if user has logged in the system
#then ,copy a file to his or her file
#else,display an error information
echo "Try in the user name."
read user
if
  grep $user /etc/passwd>tmp/null
  who|grep $user
then
  echo "$user has logged in the system."
  cp /tmp/null tmp1
  rm /tmp/null
else
  echo "$user has not logged in the system."
fi

_________________________________----
done

input:
bash<ex1
output:
try in the user name.
Usage:grep [OPTION]...PATTERN [FILE]
Try `grep --help` for more information
has not logged in the system.      
最好将这两句
grep $user /etc/passwd>tmp/null
who|grep $user
改一下
grep $user /etc/passwd >/tmp/null
who|grep $user >>/tmp/null      
还是不行!
又是提示grep用法错误.


我怀疑是空格使用不对!
你说说使用空格的规折吧!      
详细的我也不知道,大部分都是试出来的,一般命令中各个参数之间要加上空格来区分,[]作为判断条件时要留空格。大家一块总结吧!      
呵呵!那我也试试,但这个脚本太危险了。找个一般的。      
read user 时你是不是直接回车了?