[root@test script]# sh hashtag.sh 0 [root@test script]# sh hashtag.sh 123 3 [root@test script]# sh hashtag.sh `seq 300` 300
1 2 3 4 5 6 7 8 9
[root@test script]# cat example.sh #!/bin/bash #Example if [ $# -ne 2 ];then echo"Error, please enter two parameters." exit 1 else echo"You did a good job." fi
1 2 3 4 5 6
[root@test script]# sh example.sh a Error, please enter two parameters. [root@test script]# sh example.sh a b You did a good job. [root@test script]# sh example.sh a b c Error, please enter two parameters.
[byrd@LAMP script]$ pwd /byrd/script [byrd@LAMP script]$ echo $? 0#运行成功 [byrd@LAMP script]$ ls /root ls: cannot open directory /root: Permission denied [byrd@LAMP script]$ echo $? 2#权限拒绝 [byrd@LAMP script]$ hahaha -bash:hahaha: command not found [byrd@LAMP script]$ echo $?
127#未找到该命令
###########################################
1 2 3 4 5 6 7 8 9
[byrd@LAMP ~]$ cat /byrd/script/question_mark.sh #!/bin/bash #Example ls -al /root >/dev/null 2>&1 if [ $? -eq 0 ];then echo"User is root" else echo"The user is not root" fi
1 2 3 4 5
[root@LAMP script]# sh question_mark.sh User is root [root@LAMP script]# su - byrd [byrd@LAMP ~]$ sh /byrd/script/question_mark.sh The user is not root