- #!/bin/bash
- if test $# -ne 1
- then
- echo "Usage: $0: you have to contain an argument"
- exit 1
- fi
- if test -f "$1"
- then
- FileName="$1"
- rm $FileName
- fi
- if test -d "$1"
- then
- DirectoryName="$1"
- rm -rf $DirectoryName
- fi
- exit 0
- #!/bin/bash
- if test $# -ne 1 #if the argument number is not 1
- then
- echo "Usage: $0 ordinary_file" # output usage
- exit 1
- fi
- if test -f "$1"
- then
- FileName="$1" #file name
- set $(ls -il $FileName) #set the output of the cmd as environment variable
- #set `ls -il $FileName`
- FileOwner="$4" #file owner
- date1="$7" # year, moth, day
- date2="$8" #time
- echo "The owner of $FileName is: $FileOwner"
- echo "The last modified date is: $date1 $date2"
- exit 0
- fi
- echo "$0: argument must be an ordinary file" #output usage if the argument is not an ordinary file
- exit 1
shell 读文件!!!
很好的博文!!!
首次用shell,真心不习惯!
#!/bin/bash
echo "Welcome to Homework Management System"
echo "Enter Your Choice"
echo "1-administrator 2-teacher 3-student"
read choice #user's choice
if [ $choice -eq "1" ]
then
echo "enter username:"
read username #read username
echo "enter password:"
read password #read password
flag=0
more admin | while read uname passwd
do
if [ $uname = $username -a $passwd = $password ]
then
flag=1 #if sucessfully login, set flag to be 1
break
fi
done #end while
if [ $flag = 1 ]
then
echo "username or password error"
exit 1
else
echo "succeed"
#
fi
fi
阅读(537) | 评论(0) | 转发(0) |