{"rsdb":{"rid":"384618","subhead":"","postdate":"0","aid":"267717","fid":"103","uid":"1","topic":"1","content":"
\n

1. \u7f16\u5199\u51fd\u6570\uff0c\u5b9e\u73b0\u6253\u5370\u7eff\u8272OK\u548c\u7ea2\u8272FAILED \u5224\u65ad\u662f\u5426\u6709\u53c2\u6570\uff0c\u5b58\u5728\u4e3aOk\uff0c\u4e0d\u5b58\u5728\u4e3aFAILED<\/h1> \n
[root@template shellScript]# cat ex1.sh\n# \u7f16\u5199\u51fd\u6570\uff0c\u5b9e\u73b0\u6253\u5370\u7eff\u8272OK\u548c\u7ea2\u8272FAILED \u5224\u65ad\u662f\u5426\u6709\u53c2\u6570\uff0c\u5b58\u5728\u4e3aOk\uff0c\u4e0d\u5b58\u5728\u4e3aFAILED\n#!\/bin\/bash\nfun(){\nif [ $# -ne 0 ]\nthen\n        echo -e "\\033[32m OK \\033[0m"\nelse\n        echo -e "\\033[31m FAILED \\033[0m"\nfi\n}\nread -p "plz input sth..." str\nfun $str\n[root@template shellScript]# .\/ex1.sh\nplz input sth...1qw11d1d\n OK\n[root@template shellScript]# .\/ex1.sh\nplz input sth...\n FAILED\n<\/code><\/pre> \n 

\u8fd0\u884c\u6548\u679c\u56fe\uff1a
\"\"<\/p> \n

2. \u7f16\u5199\u51fd\u6570\uff0c\u5b9e\u73b0\u5224\u65ad\u662f\u5426\u65e0\u4f4d\u7f6e\u53c2\u6570\uff0c\u5982\u65e0\u53c2\u6570\uff0c\u63d0\u793a\u9519\u8bef<\/h1> \n
[root@template shellScript]# cat ex2.sh\n# \u7f16\u5199\u51fd\u6570\uff0c\u5b9e\u73b0\u5224\u65ad\u662f\u5426\u65e0\u4f4d\u7f6e\u53c2\u6570\uff0c\u5982\u65e0\u53c2\u6570\uff0c\u63d0\u793a\u9519\u8bef\n#!\/bin\/bash\nfun() {\n  if [ $# -eq 0 ]\n  then\n    echo "\u65e0\u4f4d\u7f6e\u53c2\u6570"\n  else\n    echo "\u4f4d\u7f6e\u53c2\u6570\u4e3a$@"\n  fi\n}\n\nread -p "plz input sth..." str\nfun $str\n<\/code><\/pre> \n 

\u8fd0\u884c\u622a\u56fe\uff1a
\"\"<\/p> \n

3. \u7f16\u5199\u51fd\u6570\u5b9e\u73b0\u4e24\u4e2a\u6570\u5b57\u505a\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u6700\u5927\u503c<\/h1> \n
# \u6b64\u65b9\u6cd5\u4e0d\u80fd\u6bd4\u8f83\u8d1f\u6570\u7684\u5927\u5c0f\n[root@template shellScript]# cat ex3.sh\n# \u7f16\u5199\u51fd\u6570\u5b9e\u73b0\u4e24\u4e2a\u6570\u5b57\u505a\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u6700\u5927\u503c\n#!\/bin\/bash\nfun(){\n# \u5224\u65ad\u8f93\u5165\u662f\u5426\u662f\u6570\u5b57\nif [[ $a =~ ^[0-9]*$ ]] && [[ $b =~ ^[0-9]*$ ]]\nthen\n        # \u6bd4\u8f83\u5927\u5c0f\n        if [ $a -gt $b ]\n        then\n                echo "$a > $b"\n        elif [ $a -lt $b ]\n        then\n                echo "$a < $b"\n        else\n                echo "$a = $b"\n        fi\nelse\n        echo "\u8bf7\u8f93\u5165\u4fe9\u4e2a\u6570\u5b57\uff01\uff01\uff01"\nfi\n}\n\n\n# \u8f93\u5165\u8d1f\u6570\u4e5f\u53ef\u4ee5\u6bd4\u8f83\u5927\u5c0f\n# read -p "plz input two num:" a b\nread -p "plz input num1:" a\nread -p "plz input num2:" b\nfun $a $b\n<\/code><\/pre> \n 

\u6d4b\u8bd5\u622a\u56fe\uff1a
\"\"<\/p> \n

\u65b9\u5f0f\u4e8c\uff1a<\/p> \n

[root@template shellScript]# cat .\/ex3_2.sh\n#!\/bin\/bash\nread -p "please input two number:" a b\nfun(){\n[ -z "$a" -o -z "$b" ] && {\necho "please input 'two' number"\nexit 1\n}\nexpr $a + 10 &>\/dev\/null\nreturn_a=$?\nexpr $b + 10 &>\/dev\/null\nreturn_b=$?\n[ "$return_a" -eq 0 -a "$return_b" -eq 0 ] || {\necho "please input two 'number'"\nexit 2\n}\n[ "$a" -lt "$b" ] && {\necho "$a < $b"\nexit 0\n}\n[ "$a" -eq "$b" ] && {\necho "$a = $b"\nexit 0\n}\n[ "$a" -gt "$b" ] && {\necho "$a > $b"\nexit 0\n}\n}\nfun $a $b\n<\/code><\/pre> \n 

\u8fd0\u884c\u622a\u56fe\uff1a
\"\"<\/p> \n<\/div>","orderid":"0","title":"Shell\u51fd\u6570\u7ec3\u4e60","smalltitle":"","mid":"0","fname":"Linux","special_id":"0","bak_id":"0","info":"0","hits":"21","pages":"1","comments":"0","posttime":"2023-07-23 13:35:20","list":"1690090520","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Shell<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"119.59.235.169","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Shell\u51fd\u6570\u7ec3\u4e60","lastview":"1712444869","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}