{"id":1247,"date":"2023-09-02T14:06:21","date_gmt":"2023-09-02T06:06:21","guid":{"rendered":"https:\/\/www.qiangzhenshuai.com\/?p=1247"},"modified":"2023-12-01T11:10:22","modified_gmt":"2023-12-01T03:10:22","slug":"shell","status":"publish","type":"post","link":"https:\/\/www.qiangzhenshuai.com\/?p=1247","title":{"rendered":"SHELL-\u73af\u5883\u53d8\u91cf"},"content":{"rendered":"<h1>1.\u52a0export\u548c\u4e0d\u52a0\u7684\u533a\u522b<\/h1>\n<p>\u5728Shell\u811a\u672c\u4e2d\uff0c`export`\u547d\u4ee4\u7528\u4e8e\u5c06\u53d8\u91cf\u5bfc\u51fa\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u4f7f\u5176\u5728\u811a\u672c\u4e4b\u5916\u4e5f\u53ef\u88ab\u5176\u4ed6\u7a0b\u5e8f\u6216\u5b50\u8fdb\u7a0b\u8bbf\u95ee\u3002\u4e0d\u5e26`export`\u7684\u53d8\u91cf\u4ec5\u5728\u5f53\u524dShell\u811a\u672c\u7684\u4f5c\u7528\u57df\u4e2d\u53ef\u89c1\u3002<\/p>\n<p>\u533a\u522b\u5982\u4e0b\uff1a<\/p>\n<p>\u53d8\u91cf\u4f5c\u7528\u8303\u56f4\uff1a\u4f7f\u7528`export`\u547d\u4ee4\u5bfc\u51fa\u7684\u53d8\u91cf\u53ef\u4ee5\u88ab\u5f53\u524dShell\u811a\u672c\u4ee5\u53ca\u5b50\u8fdb\u7a0b\u6216\u5176\u4ed6\u7a0b\u5e8f\u8bbf\u95ee\uff0c\u800c\u4e0d\u5e26`export`\u7684\u53d8\u91cf\u4ec5\u5728\u5f53\u524dShell\u811a\u672c\u5185\u90e8\u53ef\u89c1\u3002<\/p>\n<p>\u5b50\u8fdb\u7a0b\u8bbf\u95ee\uff1a\u4f7f\u7528`export`\u5bfc\u51fa\u7684\u53d8\u91cf\u53ef\u4ee5\u5728\u5f53\u524dShell\u811a\u672c\u7684\u5b50\u8fdb\u7a0b\u4e2d\u8bbf\u95ee\uff0c\u800c\u4e0d\u5e26`export`\u7684\u53d8\u91cf\u4e0d\u53ef\u5728\u5b50\u8fdb\u7a0b\u4e2d\u8bbf\u95ee\u3002<\/p>\n<p>\u73af\u5883\u53d8\u91cf\uff1a\u4f7f\u7528`export`\u5bfc\u51fa\u7684\u53d8\u91cf\u5c06\u6210\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u88ab\u5176\u4ed6\u7a0b\u5e8f\u6216Shell\u811a\u672c\u8bbf\u95ee\u3002\u800c\u4e0d\u5e26`export`\u7684\u53d8\u91cf\u4e0d\u4f1a\u6210\u4e3a\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u603b\u4e4b\uff0c\u4f7f\u7528`export`\u547d\u4ee4\u53ef\u4ee5\u5c06\u53d8\u91cf\u5bfc\u51fa\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u4f7f\u5176\u5728\u811a\u672c\u4e4b\u5916\u7684\u8303\u56f4\u4e5f\u53ef\u88ab\u8bbf\u95ee\u548c\u4f7f\u7528\u3002\u4e0d\u5e26`export`\u7684\u53d8\u91cf\u5219\u4ec5\u5728\u5f53\u524dShell\u811a\u672c\u7684\u4f5c\u7528\u57df\u5185\u53ef\u89c1<\/p>\n<h2>\u73af\u5883\u53d8\u91cf\u521d\u59cb\u5316\u4e0e\u5bf9\u5e94\u6587\u4ef6\u7684\u751f\u6548\u987a\u5e8f<\/h2>\n<p><a href=\"https:\/\/www.qiangzhenshuai.com\/?attachment_id=1254\" rel=\"attachment wp-att-1254\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1254\" src=\"https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u73af\u5883\u53d8\u91cf\u521d\u59cb\u5316\u4e0e\u5bf9\u5e94\u6587\u4ef6\u7684\u751f\u6548\u987a\u5e8f.png?resize=640%2C301&#038;ssl=1\" alt=\"\" width=\"640\" height=\"301\" srcset=\"https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u73af\u5883\u53d8\u91cf\u521d\u59cb\u5316\u4e0e\u5bf9\u5e94\u6587\u4ef6\u7684\u751f\u6548\u987a\u5e8f.png?w=812&amp;ssl=1 812w, https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u73af\u5883\u53d8\u91cf\u521d\u59cb\u5316\u4e0e\u5bf9\u5e94\u6587\u4ef6\u7684\u751f\u6548\u987a\u5e8f.png?resize=300%2C141&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u73af\u5883\u53d8\u91cf\u521d\u59cb\u5316\u4e0e\u5bf9\u5e94\u6587\u4ef6\u7684\u751f\u6548\u987a\u5e8f.png?resize=768%2C361&amp;ssl=1 768w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u540e\u9996\u5148\u4f1a\u52a0\u8f7d\/etc\/profile\u5168\u5c40\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff0c\u52a0\u8f7d\u5b8c\u540e\uff0c\u6267\u884c\/etc\/profile.d\u76ee\u5f55\u4e0b\u7684\u811a\u672c\u6587\u4ef6\uff08\u5982\uff1a\u7cfb\u7edf\u7684\u5b57\u7b26\u96c6\u8bbe\u7f6e\/etc\/sysconfigil8n\uff09,\u7136\u540e\u5728\u8fd0\u884c$HOME\/.bash_profile\uff08\u7528\u6237\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\uff0c\u5728\u8fd9\u6587\u4ef6\u91cc\u4f1a\u627e$HOME\/.bashrc\uff08\u7528\u6237\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\uff0c\u6709\u5c31\u6267\u884c\uff0c\u6ca1\u6709\u5c31\u4e0d\u6267\u884c\u3002\u5728$HOME\/.bashrc\u627e\/etc\/bashrc\uff08\u5168\u5c40\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\u6709\u5c31\u6267\u884c\uff0c\u6ca1\u6709\u5c31\u4e0d\u6267\u884c\u3002\u5982\u679c\u5e0c\u671b\u7528\u6237\u7684Shell\u4e0d\u662f\u767b\u9646\u65f6\u542f\u52a8\u7684\uff08\u5982\uff1a\u624b\u52a8\u6572\u4e0bbash\u65f6\u542f\u52a8\u6216\u8005\u8fdc\u7a0bssh\u8fde\u63a5\u60c5\u51b5\uff09\uff0c\u975e\u767b\u9646Shell\u53ea\u4f1a\u52a0\u8f7d$HOME\/.bashrc\uff08\u7528\u6237\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\uff0c\u5e76\u4f1a\u53bb\u627e\/etc\/bashrc\uff08\u5168\u5c40\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\u3002\u5373\u975e\u767b\u9646Shell\u60f3\u8bfb\u5230\u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\uff0c\u9700\u8981\u5c06\u53d8\u91cf\u8bbe\u5b9a\u7b49\u5199\u5165$HOME\/.bashrc\uff08\u7528\u6237\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\u6216etc\/bashrc\uff08\u5168\u5c40\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff09\u4e0d\u662f$HOME\/.bash_profile\u6216\/etc\/profile\u3002\u3002\u3002<\/p>\n<h1>2.\u53d8\u91cf\u503c\u7684\u5b9a\u4e49<\/h1>\n<p>\u53d8\u91cf\u540d=value\u00a0 \u00a0 \u00a0 \u00a0#\u4e0d\u52a0\u5f15\u53f7\u65f6\uff0c\u503c\u91cc\u6709\u53d8\u91cf\u7684\u4f1a\u88ab\u89e3\u6790\u540e\u8f93\u51fa\u3002<\/p>\n<p>\u53d8\u91cf\u540d=&#8217;value&#8217;\u00a0 \u00a0 \u00a0#\u8f93\u51fa\u53d8\u91cf\u5185\u5bb9\u65f6\u5355\u5f15\u53f7\u91cc\u662f\u4ec0\u4e48\u5c31\u8f93\u51fa\u4ec0\u4e48\uff0c\u4e0d\u7ba1\u4ec0\u4e48\u90fd\u539f\u6837\u8f93\u51fa\u3002<\/p>\n<p>\u53d8\u91cf\u540d=&#8221;value&#8221;\u00a0 \u00a0 #\u8f93\u51fa\u53d8\u91cf\u5185\u5bb9\u65f6\u5f15\u53f7\u91cc\u7684\u53d8\u91cf\u548c\u547d\u4ee4\u7ecf\u8fc7\u89e3\u6790\u540e\u8f93\u51fa\u3002<\/p>\n<h2>\u547d\u4ee4\u7ed3\u679c\u4f5c\u4e3a\u7684\u53d8\u91cf\u5185\u5bb9\u6765\u8d4b\u503c<\/h2>\n<p>\u53d8\u91cf\u540d=`mkdir`\u00a0 \u00a0 #\u8fd9\u91cc\u662f\u53cd\u5f15\u53f7\uff0c<\/p>\n<p>\u53d8\u91cf\u540d=$(mkdir)\u00a0 #\u628a\u547d\u4ee4$()\u62ec\u8d77\u6765\uff0c\u6765\u8d4b\u503c\u3002<\/p>\n<p>\u5355\u5f15\u53f7\uff1a\u6240\u89c1\u5373\u6240\u5f97\uff0c\u5403\u5565\u5410\u5565\uff0c\u539f\u5c01\u4e0d\u52a8\u7684\u8f93\u51fa\u3002<br \/>\n\u53cc\u5f15\u53f7\uff1a\u4e0e\u5355\u5f15\u53f7\u7c7b\u4f3c\uff0c\u7279\u6b8a\u7b26\u53f7\u4f1a\u88ab\u89e3\u6790(\u8fd0\u884c)\uff1a<span id=\"MathJax-Element-1-Frame\" class=\"mjx-chtml MathJax_CHTML\" style=\"margin: 0px; padding: 1px 0px; display: inline-block; line-height: 0; text-indent: 0px; text-align: left; text-transform: none; font-style: normal; font-weight: 400; font-size: 16.38px; letter-spacing: normal; overflow-wrap: normal; word-spacing: 0px; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; color: #403226; font-family: 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; \/&gt;\"><span id=\"MJXc-Node-1\" class=\"mjx-math\" aria-hidden=\"true\"><span id=\"MJXc-Node-2\" class=\"mjx-mrow\"><\/span><\/span><\/span>() &#8220;<br \/>\n\u4e0d\u52a0\u5f15\u53f7\uff1a\u4e0e\u53cc\u5f15\u53f7\u7c7b\u4f3c\uff0c\u5982\u679c\u51fa\u73b0\u7a7a\u683c\uff0c\u4e0d\u4f1a\u7b97\u4f5c\u4e00\u4e2a\u6574\u4f53\u3002<br \/>\n\u53cd\u5f15\u53f7\uff1a\u5148\u6267\u884c\u53cd\u5f15\u53f7\u91cc\u9762\u7684\u547d\u4ee4\uff0c\u628a\u6267\u884c\u7684\u7ed3\u679c\u663e\u793a\u51fa\u6765\u3002<\/p>\n<p><a href=\"https:\/\/www.qiangzhenshuai.com\/?attachment_id=1266\" rel=\"attachment wp-att-1266\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1266\" src=\"https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u53d8\u91cf\u503c\u7684\u5b9a\u4e49.png?resize=640%2C232&#038;ssl=1\" alt=\"\" width=\"640\" height=\"232\" srcset=\"https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u53d8\u91cf\u503c\u7684\u5b9a\u4e49.png?w=646&amp;ssl=1 646w, https:\/\/i0.wp.com\/www.qiangzhenshuai.com\/wp-content\/uploads\/2023\/09\/shell\u53d8\u91cf\u503c\u7684\u5b9a\u4e49.png?resize=300%2C109&amp;ssl=1 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<h1>3.\u67e5\u770b\u73af\u5883\u53d8\u91cf<\/h1>\n<h4>set\u547d\u4ee4\u8f93\u51fa\u6240\u6709\u7684\u53d8\u91cf\uff0c\u5305\u62ec\u5168\u5c40\u53d8\u91cf\u548c\u5c40\u90e8\u53d8\u91cf<\/h4>\n<p>[root@shell01 ~]$ set<\/p>\n<pre>APACHEERR=hello world\r\nBASH=\/bin\/bash\r\nBASH_ALIASES=()\r\nBASH_ARGC=()\r\nBASH_ARGV=()\r\nBASH_CMDS=()\r\nBASH_LINENO=()\r\nBASH_SOURCE=()\r\nBASH_VERSINFO=([0]=\"4\" [1]=\"1\" [2]=\"2\" [3]=\"1\" \r\n#\u4e2d\u95f4\u548c\u7ed3\u5c3e\u7701\u7565\u82e5\u5e72\u4ee3\u7801<\/pre>\n<h4>env(printenv)\u547d\u4ee4\u53ea\u663e\u793a\u5168\u5c40\u53d8\u91cf<\/h4>\n<pre>[root@shell01 ~]$ env\r\nXDG_SESSION_ID=10\r\nHOSTNAME=shell01\r\nTERM=linux\r\nSHELL=\/bin\/bash\r\nHISTSIZE=1000\r\nSSH_CLIENT=10.0.0.1 8593 22\r\nSSH_TTY=\/dev\/pts\/0\r\nUSER=root\r\nLS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:\r\nMAIL=\/var\/spool\/mail\/root\r\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/root\/bin\r\nPWD=\/root\r\nLANG=en_US.UTF-8\r\nPS1=[\\[\\e[34;1m\\]\\u@\\[\\e[0m\\]\\[\\e[32;1m\\]\\H\\[\\e[0m\\] \\[\\e[31;1m\\]\\w\\[\\e[0m\\]]\\\\$ \r\nHISTCONTROL=ignoredups\r\nSHLVL=1\r\nHOME=\/root\r\nLOGNAME=root\r\nSSH_CONNECTION=10.0.0.1 8593 10.0.0.65 22\r\nLESSOPEN=||\/usr\/bin\/lesspipe.sh %s\r\nXDG_RUNTIME_DIR=\/run\/user\/0\r\n_=\/usr\/bin\/env<\/pre>\n<h3>\u67e5\u770b\u8bbe\u7f6e\u7684\u53d8\u91cf<\/h3>\n<h4>\u6dfb\u52a0<\/h4>\n<p>[root@shell01 ~]$ name=hostname<br \/>\n[root@shell01 ~]$ echo $name<br \/>\nhostname<\/p>\n<p>set\u53ef\u4ee5\u8bbe\u7f6e\u67d0\u4e2a\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002\u6e05\u9664\u73af\u5883\u53d8\u91cf\u7684\u503c\u7528unset\u547d\u4ee4\u3002\u5982\u679c\u672a\u6307\u5b9a\u503c\uff0c\u5219\u8be5\u53d8\u91cf\u503c\u5c06\u88ab\u8bbe\u4e3aNULL<\/p>\n<h4>\u5220\u9664<\/h4>\n<p>[root@shell01 ~]$ echo $name<br \/>\nhostname<br \/>\n[root@shell01 ~]$ uns<br \/>\nunset unshare<br \/>\n[root@shell01 ~]$ unset name<br \/>\n[root@shell01 ~]$ echo $name<\/p>\n<h1 class=\"Post-Title\">4.Shell \u811a\u672c\u4e2d &#8216;$&#8217; \u7b26\u53f7\u7684\u591a\u79cd\u7528\u6cd5<\/h1>\n<p>$0\uff1aShell \u7684\u547d\u4ee4\u672c\u8eab1 \u52301 \u52309\uff1a\u8868\u793a Shell \u7684\u7b2c\u51e0\u4e2a\u53c2\u6570<br \/>\n$n\uff1a\u8868\u793a\u811a\u672c\u7684\u7b2cn\u4e2a\u53c2\u6570 n\u4e3a\u6570\u5b57 0\u5df2\u7ecf\u88ab\u811a\u672c\u540d\u79f0\u5360\u7528 \u4ece1\u5f00\u59cb \u4ece$9\u540e \u9700\u8981\u52a0\u82b1\u62ec\u53f7\u5f15\u8d77\u6765\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53${10}<br \/>\n$?\uff1a\u663e\u793a\u6700\u540e\u547d\u4ee4\u7684\u6267\u884c\u60c5\u51b5\uff0c0\u4e3a\u6210\u529f \u975e0\u5931\u8d25 \u8fd4\u56de\u503c0-255 \u53ef\u4ee5\u81ea\u5b9a\u4e49\u8fd4\u56de\u503c<br \/>\n$#\uff1a\u4f20\u9012\u5230\u811a\u672c\u7684\u53c2\u6570\u4e2a\u6570<br \/>\n$$\uff1a\u811a\u672c\u8fd0\u884c\u7684\u5f53\u524d\u8fdb\u7a0b ID\uff08PID\uff09 \u53f7<br \/>\n$*\uff1a\u4ee5\u4e00\u4e2a\u5355\u5b57\u7b26\u4e32\u663e\u793a\u6240\u6709\u5411\u811a\u672c\u4f20\u9012\u7684\u53c2\u6570\uff0c\u8868\u793a\u4f20\u53c2\u7684\u6240\u6709\u53c2\u6570 \u4e0d\u52a0\u53cc\u5f15\u53f7\u548c$@\uff1a\u76f8\u540c \u52a0\u4e0a\u53cc\u5f15\u53f7 \u8868\u793a\u4e3a\u4e00\u4e2a\u53c2\u6570 \u5728\u811a\u672c\u4e2d\u76f8\u540c \u5faa\u73af\u4f53\u4e0d\u540c<br \/>\n$!\uff1a\u540e\u53f0\u8fd0\u884c\u7684\u6700\u540e\u4e00\u4e2a\u8fdb\u7a0b\u7684 ID \u53f7<br \/>\n$-\uff1a\u663e\u793a Shell \u4f7f\u7528\u7684\u5f53\u524d\u9009\u9879<br \/>\n$_\uff1a\u8868\u793a\u4e0a\u4e00\u4e2a\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u3002\u901a\u5e38\u7528\u4e8e\u5feb\u901f\u91cd\u590d\u4e0a\u4e00\u4e2a\u547d\u4ee4\u7684\u6700\u540e\u4e00\u4e2a\u53c2\u6570<\/p>\n<h1>5.<span role=\"heading\" aria-level=\"2\">shell-\u53d8\u91cf\u8f93\u5165\u5185\u7f6eread\u547d\u4ee4\u8be6\u89e3<\/span><\/h1>\n<p class=\"code-snippet__js\" data-lang=\"cs\">-p\uff1a\u7ed9\u63d0\u793a\u8bed<br \/>\n-s\uff1a\u9690\u85cf\u7528\u6237\u8f93\u5165\u7684\u4fe1\u606f<br \/>\n-t\uff1a\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff08s\uff09<br \/>\n-a\uff1a\u540e\u8ddf\u4e00\u4e2a\u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u4f1a\u88ab\u8ba4\u4e3a\u662f\u4e2a\u6570\u7ec4\uff0c\u7136\u540e\u7ed9\u5176\u8d4b\u503c\uff0c\u9ed8\u8ba4\u662f\u4ee5\u7a7a\u683c\u4e3a\u5206\u5272\u7b26\u3002<br \/>\n-n\uff1a\u6307\u5b9a\u5b57\u7b26\u4e2a\u6570<\/p>\n<h4 data-lang=\"cs\">\u628a\u52a0\u51cf\u4e58\u9664\u8ba1\u7b97\u7684\u811a\u672c\u6539\u6210\u901a\u8fc7read\u65b9\u5f0f\u8bfb\u5165\u6574\u6570\u53d8\u91cf<\/h4>\n<p>[root@shell01 \/server\/scripts]$ cat jiajian.sh<br \/>\n#!\/bin\/bash<br \/>\na=$1<br \/>\nb=$2<\/p>\n<p>echo &#8220;a-b=$(( $a &#8211; $b ))&#8221;<br \/>\necho &#8220;a+b=$(( $a + $b ))&#8221;<br \/>\necho &#8220;a*b=$(( $a * $b ))&#8221;<br \/>\necho &#8220;a\/b=$(( $a \/ $b ))&#8221;<br \/>\necho &#8220;a**b=$(( $a ** $b ))&#8221;<br \/>\necho &#8220;a%b=$(( $a %$b ))&#8221;<br \/>\n[root@shell01 \/server\/scripts]$ sh jiajian.sh 9 6<br \/>\na-b=3<br \/>\na+b=15<br \/>\na*b=54<br \/>\na\/b=1<br \/>\na**b=531441<br \/>\na%b=3<\/p>\n<h4>\u4fee\u6539\u6210read<\/h4>\n<p>[root@shell01 \/server\/scripts]$ cat jiajian01.sh<br \/>\n#!\/bin\/bash<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u6570\u5b57: &#8221; a b<\/p>\n<p>echo &#8220;a-b=$(( $a &#8211; $b ))&#8221;<br \/>\necho &#8220;a+b=$(( $a + $b ))&#8221;<br \/>\necho &#8220;a*b=$(( $a * $b ))&#8221;<br \/>\necho &#8220;a\/b=$(( $a \/ $b ))&#8221;<br \/>\necho &#8220;a**b=$(( $a ** $b ))&#8221;<br \/>\necho &#8220;a%b=$(( $a %$b ))&#8221;<br \/>\n[root@shell01 \/server\/scripts]$ sh jiajian01.sh<br \/>\n\u8bf7\u8f93\u5165\u6570\u5b57: 9 3<br \/>\na-b=6<br \/>\na+b=12<br \/>\na*b=27<br \/>\na\/b=3<br \/>\na**b=729<br \/>\na%b=0<\/p>\n<h4>read\u4fee\u6539\u4e3b\u673a\u540d\u79f0\u548cIP\u5730\u5740<\/h4>\n<p>[root@shell01 \/server\/scripts]$ cat hostname.sh<br \/>\n#!\/bin\/sh<br \/>\nIP_DIR=\/etc\/sysconfig\/network-scripts\/ifcfg-eth0<br \/>\nS_IP=`hostname -I|awk &#8216;{print $1}&#8217;`<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u4f60\u8981\u4fee\u6539\u7684\u4e3b\u673a\u540d\u79f0: &#8221; name<br \/>\nhostnamectl set-hostname $name<\/p>\n<p>read -p &#8220;\u8bf7\u8f93\u5165\u4f60\u8981\u4fee\u6539\u7684IP\u5730\u5740: &#8221; D_IP<br \/>\nsed -i &#8220;s#$S_IP#10.0.0.$D_IP#g&#8221; $IP_DIR<br \/>\ngrep IPADDR $IP_DIR<\/p>\n<h1>6.\u53d8\u91cf\u7684\u5b50\u4e32<\/h1>\n<p><strong>\uff08\u7a7a\u683c\u9700\u8981\u7b97\u4e00\u4e2a\u5b57\u7b26\uff09<\/strong><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td><strong>\u8868\u8fbe\u5f0f<\/strong><\/td>\n<td><strong>\u8bf4\u660e<\/strong><\/td>\n<\/tr>\n<tr>\n<td>${parameter}<\/td>\n<td>\u8fd4\u56de\u53d8\u91cf$parameter\u7684\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>${#parameter}<\/td>\n<td>\u8fd4\u56de\u53d8\u91cf$parameter\u5185\u5bb9\u7684\u957f\u5ea6(\u6309\u5b57\u7b26)\uff0c\u4e5f\u9002\u7528\u4e8e\u7279\u6b8a\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td>${parameter:offset}<\/td>\n<td>\u5728\u53d8\u91cf${parameter}\u4e2d\uff0c\u4ece\u4f4d\u7f6eoffset\u4e4b\u540e\u5f00\u59cb\u63d0\u53d6\u5b50\u4e32\u5230\u7ed3\u5c3e<\/td>\n<\/tr>\n<tr>\n<td>${parameter:offset\uff1alength}<\/td>\n<td>\u5728\u53d8\u91cf${parameter}\u4e2d\uff0c\u4ece\u4f4d\u7f6eoffset\u4e4b\u540e\u5f00\u59cb\u63d0\u53d6\u957f\u5ea6\u4e3alength\u7684\u5b50\u4e32<\/td>\n<\/tr>\n<tr>\n<td>${parameter#word}<\/td>\n<td>\u4ece\u53d8\u91cf${parameter}\u5f00\u5934\u5f00\u59cb\u5220\u9664\u6700\u77ed\u5339\u914d\u7684word\u5b50\u4e32<\/td>\n<\/tr>\n<tr>\n<td>${parameter##word}<\/td>\n<td>\u4ece\u53d8\u91cf${parameter}\u5f00\u5934\u5f00\u59cb\u5220\u9664\u6700\u957f\u5339\u914d\u7684word\u5b50\u4e32<\/td>\n<\/tr>\n<tr>\n<td>${parameter%word}<\/td>\n<td>\u4ece\u53d8\u91cf${parameter}\u7ed3\u5c3e\u5f00\u59cb\u5220\u9664\u6700\u77ed\u5339\u914d\u7684word\u5b50\u4e32<\/td>\n<\/tr>\n<tr>\n<td>${parameter%%word}<\/td>\n<td>\u4ece\u53d8\u91cf${parameter}\u7ed3\u5c3e\u5f00\u59cb\u5220\u9664\u6700\u957f\u5339\u914d\u7684word\u5b50\u4e32<\/td>\n<\/tr>\n<tr>\n<td>${parameter\/pattern\/string}<\/td>\n<td>\u4f7f\u7528string\u4ee3\u66ff\u7b2c\u4e00\u4e2a\u5339\u914d\u7684pattern<\/td>\n<\/tr>\n<tr>\n<td>${parameter\/\/pattern\/string}<\/td>\n<td>\u4f7f\u7528string\u4ee3\u66ff\u6240\u6709\u5339\u914d\u7684pattern<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 class=\"md-end-block md-heading md-focus\"><span class=\"md-plain md-expand\">\u53d6\u53d8\u91cf\u7684\u957f\u5ea6<\/span><\/h4>\n<p>[root@shell ~]$ sentence=&#8217;go up to heaven and enter the earth&#8217;<br \/>\n[root@shell ~]$ echo $sentence<br \/>\ngo up to heaven and enter the earth<\/p>\n<p>[root@shell ~]$ echo $sentence | wc -L<br \/>\n35<\/p>\n<p>[root@shell ~]$ expr length &#8220;$sentence&#8221;<br \/>\n35<\/p>\n<p>[root@shell ~]$ echo $sentence|awk &#8216;{print length($0)}&#8217;<br \/>\n35<\/p>\n<p>[root@shell ~]$ echo ${#sentence}<br \/>\n35<\/p>\n<h3 class=\"md-end-block md-heading md-focus\"><span class=\"md-plain md-expand\">\u622a\u53d6\u53d8\u91cf\u7684\u5185\u5bb9<\/span><\/h3>\n<p>[root@shell ~]$ echo $sentence<br \/>\ngo up to heaven and enter the earth<\/p>\n<h4>\u4ece\u7b2c2\u4e2a\u5b57\u7b26\u4e4b\u540e\u5f00\u59cb\u622a\u53d6\uff0c\u9ed8\u8ba4\u622a\u53d6\u540e\u9762\u5b57\u7b26\u7684\u5168\u90e8\uff0c\u7b2c2\u4e2a\u5b57\u7b26\u4e0d\u5305\u542b\u5728\u5185\uff0c\u4e5f\u53ef\u7406\u89e3\u4e3a\u5220\u9664\u524d\u9762\u7684\u591a\u4e2a\u5b57\u7b26<\/h4>\n<p>[root@shell ~]$ echo ${sentence:2}<br \/>\nup to heaven and enter the earth<\/p>\n<h4>\u622a\u53d6\u53d8\u91cf\u7684\u5185\u5bb9\uff0c\u4ece\u7b2c3\u4e2a\u5b57\u7b26\u4e4b\u540e\u5f00\u59cb\u622a\u53d6\uff0c\u622a\u53d62\u4e2a\u5b57\u7b26<\/h4>\n<p>[root@shell ~]$ echo ${sentence:3:2}<br \/>\nup<\/p>\n<h4>\u7edf\u8ba1\u51fa\u53d8\u91cf\u4e2d\u7684\u957f\u5ea6\u5c0f\u4e8e3\u7684\u503c<\/h4>\n<p>[root@shell ~]$ echo $sentence |awk &#8216;{for(i=1;i&lt;=NF;i++)if(length($i)&lt;3)print $i}&#8217;<br \/>\ngo<br \/>\nup<br \/>\nto<\/p>\n<p>[root@shell ~]$ echo $sentence|xargs -n1|awk &#8216;{if(length&lt;3)print}&#8217;<br \/>\ngo<br \/>\nup<br \/>\nto<\/p>\n<p>[root@shell \/server\/scripts]$ cat for.sh<br \/>\nfor i in go up to heaven and enter the earth<br \/>\ndo<br \/>\n[ ${#i} -lt 3 ] &amp;&amp; echo $i<br \/>\ndone<br \/>\n[root@shell \/server\/scripts]$ sh for.sh<br \/>\ngo<br \/>\nup<br \/>\nto<\/p>\n<h3>\u5220\u9664<\/h3>\n<p>[root@shell \/server\/scripts]$ url=www.feitian.com<br \/>\n[root@shell \/server\/scripts]$ echo $url<br \/>\nwww.feitian.com<\/p>\n<h4>\u4ece\u524d\u9762\u5f80\u540e\u5220\u9664 \u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26\u5339\u914d\u5b57\u7b26\u4e32<\/h4>\n<p>[root@shell \/server\/scripts]$ echo ${url#*.}<br \/>\nfeitian.com<\/p>\n<h4>\u5220\u9664\u5230\u6700\u540e\u4e00\u4e2a<\/h4>\n<p>[root@shell \/server\/scripts]$ echo ${url##*.}<br \/>\ncom<br \/>\n[root@shell \/server\/scripts]$ echo ${url#*.*.}<br \/>\ncom<\/p>\n<h4>\u4ece\u540e\u5f80\u524d\u5220\u9664<\/h4>\n<p>[root@shell \/server\/scripts]$ echo ${url%.*.*}<br \/>\nwww<\/p>\n<p>[root@shell \/server\/scripts]$ echo ${url%%.*}<br \/>\nwww<\/p>\n<p>[root@shell \/server\/scripts]$ num=100%<br \/>\n[root@shell \/server\/scripts]$ echo $num<br \/>\n100%<br \/>\n[root@shell \/server\/scripts]$ echo ${num%\\%}<br \/>\n100<\/p>\n<p>#\u8868\u793a\u4ece\u5f00\u5934\u5220\u9664\u5339\u914d\u6700\u77ed\u3002<br \/>\n##\u8868\u793a\u4ece\u5f00\u5934\u5220\u9664\u5339\u914d\u6700\u957f\u3002<br \/>\n\uff05\u8868\u793a\u4ece\u7ed3\u5c3e\u5220\u9664\u5339\u914d\u6700\u77ed\u3002<br \/>\n\uff05\uff05\u8868\u793a\u4ece\u7ed3\u5c3e\u5220\u9664\u5339\u914d\u6700\u957f\u3002<br \/>\na*c\u8868\u793a\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c*\u8868\u793a\u5339\u914d\u6240\u6709\uff0ca*c\u5339\u914d\u5f00\u5934\u4e3aa\u3001\u4e2d\u95f4\u4e3a\u4efb\u610f\u591a\u4e2a\u5b57\u7b26\u3001\u7ed3\u5c3e\u4e3ac\u7684\u5b57\u7b26\u4e32\u3002<br \/>\na*C\u8868\u793a\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c*\u8868\u793a\u5339\u914d\u6240\u6709\uff0ca*C\u5339\u914d\u5f00\u5934\u4e3aa\u3001\u4e2d\u95f4\u4e3a\u4efb\u610f\u591a\u4e2a\u5b57\u7b26\u3001\u7ed3\u5c3e\u4e3aC\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<h4>\u66ff\u6362<\/h4>\n<p>[root@shell \/server\/scripts]$ url=www.feitian.com<br \/>\n[root@shell \/server\/scripts]$ echo $URL<br \/>\nwww.feitian.com<\/p>\n<p>[root@shell \/server\/scripts]$ echo ${url\/www\/test}<br \/>\ntest.feitian.com<\/p>\n<p>[root@shell \/server\/scripts]$ echo ${url\/w\/W}<br \/>\nWww.feitian.com<\/p>\n<p>[root@shell \/server\/scripts]$ echo ${url\/\/w\/W}<br \/>\nWWW.feitian.com<\/p>\n<p>[root@shell \/server\/scripts]$ echo ${url\/m\/W}<br \/>\nwww.feitian.coW<\/p>\n<h1>7.\u6570\u503c\u8fd0\u7b97<\/h1>\n<h2 id=\"activity-name\" class=\"rich_media_title \">i++ \u548c ++i \u7684\u533a\u522b<\/h2>\n<p>\u8d4b\u503c\u987a\u5e8f\u4e0d\u540c\uff0c++i\u662f\u5148\u52a0\u540e\u8d4b\u503c\uff1bi++\u662f\u5148\u8d4b\u503c\u540e\u52a0\uff1b++i\u548ci++\u90fd\u662f\u5206\u4e24\u6b65\u5b8c\u6210\u7684\u3002<\/p>\n<p>\u6548\u7387\u4e0d\u540c\uff0c\u6bd4\u5982i=3\uff0cb=i++\u5c31\u662f\u8bf4b=3\uff0c\u5b8c\u6210\u4e4b\u540e\u8ba9i\u53d8\u62104\uff0cb=++i\u5c31\u662f\u5148\u8ba9i++\u53d8\u62104\uff0c\u7136\u540eb=4\uff0c\u5176\u4e2d++i\u6bd4i++\u6548\u7387\u8981\u9ad8\u4e9b\u3002\u4e00\u822c\u6765\u8bf4\u5728\u5faa\u73af\u57df\u91cc\u9762\uff0c\u8fd9\u4e24\u8005\u5e76\u6ca1\u6709\u4ec0\u4e48\u5f88\u5927\u7684\u533a\u522b\uff0c\u4f46\u662f\u8981\u6ce8\u610f\u5176\u751f\u5b58\u5468\u671f\uff0c\u4ee5\u53cai\u503c\u5728\u7a0b\u5e8f\u6d41\u4e2d\u7684\u53d8\u5316\u3002<\/p>\n<p>i++\u4e0d\u80fd\u4f5c\u4e3a\u5de6\u503c\uff0c\u800c++i\u53ef\u4ee5\u3002\u5de6\u503c\u662f\u5bf9\u5e94\u5185\u5b58\u4e2d\u6709\u786e\u5b9a\u5b58\u50a8\u5730\u5740\u7684\u5bf9\u8c61\u7684\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u800c\u53f3\u503c\u662f\u6240\u6709\u4e0d\u662f\u5de6\u503c\u7684\u8868\u8fbe\u5f0f\u7684\u503c\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5de6\u503c\u662f\u53ef\u4ee5\u653e\u5230\u8d4b\u503c\u7b26\u53f7\u5de6\u8fb9\u7684\u53d8\u91cf\u3002<\/p>\n<p>i++\u548c++i\u90fd\u662f\u5b9e\u73b0\u53d8\u91cfi\u7684\u81ea\u589e\uff0c\u4e24\u8005\u7684\u533a\u522b\u5728\u4e8ei++\u662f\u5148\u8fd0\u7b97\uff0c\u518d\u52a01\uff0c\u800c++i\u662f\u5148\u52a01\uff0c\u540e\u8fd0\u7b97\u3002\u4f46\u662f\u4e0d\u7ba1\u662fi++\u8fd8\u662f++i\uff0c\u6700\u540ei\u7684\u503c\u90fd\u662f\u76f8\u540c\u7684\u30025\u3001\u64cd\u4f5c\u7ed3\u679c\u4e0d\u540c\uff0c\u5bf9\u4e8en=++i,\u8fdb\u884c\u64cd\u4f5c\u540e\uff0cn\u7684\u503c\u53d1\u751f\u4e86\u6539\u53d8\uff0c\u5176\u503c\u53d8\u6210\u4e86i+1\uff0c\u5bf9\u4e8en=i++\uff0c\u8fdb\u884c\u64cd\u4f5c\u540e\uff0cn\u7684\u503c\u4e0d\u53d1\u751f\u6539\u53d8\uff0c\u5176\u503c\u4ecd\u7136\u4e3ai\u3002<\/p>\n<h2>expr\u53ea\u652f\u6301\u6574\u6570\u8fd0\u7b97<\/h2>\n<h4>\u52a0\u51cf\u4e58\u9664<\/h4>\n<p>[root@shell \/server\/scripts]$ expr 10 + 1<br \/>\n11<br \/>\n[root@shell \/server\/scripts]$ expr 10 &#8211; 1<br \/>\n9<br \/>\n[root@shell \/server\/scripts]$ expr 10 \\* 3<br \/>\n30<br \/>\n[root@shell \/server\/scripts]$ expr 10 \/ 2<br \/>\n5<\/p>\n<h4>\u5224\u65ad\u6211\u4eec\u8f93\u5165\u7684\u6570\u5b57\u662f\u5426\u4e3a\u6574\u6570<\/h4>\n<p>[root@shell \/server\/scripts]$ cat num.sh<br \/>\n#!\/bin\/sh<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570: &#8221; num<br \/>\nexpr 1 + $num &amp;&gt;\/dev\/null<br \/>\n[ $? -ne 0 ] &amp;&amp; echo &#8220;\u4f60\u8f93\u5165\u7684\u4e0d\u662f\u6574\u6570&#8221; &amp;&amp; exit<\/p>\n<p>echo $num<\/p>\n<h3>$[]\u00a0\u662f\u4e00\u79cd\u65e7\u5f0f\u7684\u6574\u6570\u8fd0\u7b97\u8bed\u6cd5\uff0c\u901a\u5e38\u7528\u4e8e\u8fdb\u884c\u7b97\u672f\u8fd0\u7b97<\/h3>\n<p>[root@shell \/server\/scripts]$ echo $[1+10]<br \/>\n11<br \/>\n[root@shell \/server\/scripts]$ echo $[1*10]<br \/>\n10<br \/>\n[root@shell \/server\/scripts]$ echo $[1-10]<br \/>\n-9<br \/>\n[root@shell \/server\/scripts]$ echo $[10-2+5]<br \/>\n13<br \/>\n[root@shell \/server\/scripts]$ echo $[2**2]<br \/>\n4<br \/>\n[root@shell \/server\/scripts]$ echo $[2^2]<br \/>\n0<br \/>\n[root@shell \/server\/scripts]$ echo $[2\/2]<\/p>\n<h3>$(())\u6ce8\u610f\u4e24\u4e2a\u5c0f\u62ec\u53f7\u662f\u505a\u8fd0\u7b97 \u4e00\u4e2a\u5c0f\u62ec\u53f7\u662f\u6267\u884c\u547d\u4ee4 $() \u8fd0\u7b97\u6548\u7387\u6700\u9ad8<\/h3>\n<p>[root@shell \/server\/scripts]$ echo $((10+2-5))<br \/>\n7<br \/>\n[root@shell \/server\/scripts]$ echo $((10+2*5))<br \/>\n20<br \/>\n[root@shell \/server\/scripts]$ echo $(((10+2)*5))<br \/>\n60<br \/>\n[root@shell \/server\/scripts]$ echo $(((10+2)\/6))<br \/>\n2<\/p>\n<h3>let\u8fd0\u7b97\u9700\u8981\u4f7f\u7528\u53d8\u91cf\u53ea\u652f\u6301\u6574\u6570\u8fd0\u7b97<\/h3>\n<p>let\u00a0\u662f\u7528\u4e8e\u6267\u884c\u7b97\u672f\u8fd0\u7b97\u7684\u5185\u7f6e\u547d\u4ee4\u3002\u5b83\u5141\u8bb8\u4f60\u5728Shell\u811a\u672c\u4e2d\u8fdb\u884c\u6574\u6570\u8fd0\u7b97\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002<\/p>\n<h3>\u52a0\u6cd5<\/h3>\n<pre>let result=5+3\r\necho $result  \r\n\u8f93\u51fa\uff1a8\r\n<\/pre>\n<h3>\u51cf\u6cd5<\/h3>\n<pre>let result=5-3\r\necho $result  \r\n\u8f93\u51fa\uff1a2\r\n<\/pre>\n<h3>\u4e58\u6cd5<\/h3>\n<pre>let result=5*3\r\necho $result  \r\n\u8f93\u51fa\uff1a15\r\n<\/pre>\n<h3>\u9664\u6cd5<\/h3>\n<pre>let result=10\/2\r\necho $result  \r\n\u8f93\u51fa\uff1a5\r\n<\/pre>\n<p>\u4e0e$[]\u3001$(())\u548cexpr\u547d\u4ee4\u4e0d\u540c\uff0clet\u547d\u4ee4\u4e0d\u9700\u8981\u5bf9\u4e58\u6cd5\u7b26\u53f7*\u8fdb\u884c\u8f6c\u4e49\u3002\u53e6\u5916\uff0c\u5b83\u4e5f\u53ea\u652f\u6301\u6574\u6570\u8fd0\u7b97\uff0c\u65e0\u6cd5\u5904\u7406\u6d6e\u70b9\u6570\u3002<\/p>\n<h4>bc \u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u5b66\u8fd0\u7b97\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u5b83\u652f\u6301\u6574\u6570\u548c\u6d6e\u70b9\u6570\u7684\u8fd0\u7b97\uff0c\u4ee5\u53ca\u5404\u79cd\u6570\u5b66\u51fd\u6570\u548c\u8868\u8fbe\u5f0f\u3002<\/h4>\n<h3>\u6574\u6570\u8fd0\u7b97<\/h3>\n<pre>[root@shell \/server\/scripts]$ echo \"5 + 3\" | bc\r\n8\r\n[root@shell \/server\/scripts]$ echo 5 + 3 | bc\r\n8\r\n<\/pre>\n<h3>\u6d6e\u70b9\u6570\u8fd0\u7b97<\/h3>\n<pre>[root@shell \/server\/scripts]$ echo \"5.5 * 2.2\" | bc\r\n12.1\r\n<\/pre>\n<h3>\u4f7f\u7528\u53d8\u91cf<\/h3>\n<pre>x=5\r\ny=3\r\necho \"$x + $y\" | bc  \r\n\u8f93\u51fa\uff1a8\r\n<\/pre>\n<h3>\u4f7f\u7528\u6570\u5b66\u51fd\u6570<\/h3>\n<pre>echo \"s(0)\" | bc -l  \r\n\u8f93\u51fa\uff1a0.00000000000000000000\r\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c-l\u00a0\u9009\u9879\u7528\u4e8e\u52a0\u8f7d\u6807\u51c6\u6570\u5b66\u5e93\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u4f7f\u7528\u6570\u5b66\u51fd\u6570\u3002<\/p>\n<p>bc\u00a0\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u590d\u6742\u7684\u6570\u5b66\u8ba1\u7b97\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u5904\u7406\u6d6e\u70b9\u6570\u65f6\uff0cbc\u00a0\u53ef\u80fd\u4f1a\u4ea7\u751f\u4e00\u4e9b\u7cbe\u5ea6\u95ee\u9898\u3002<\/p>\n<h3>awk\u8fd0\u7b97<\/h3>\n<p>[root@shell \/server\/scripts]$ awk &#8216;BEGIN{print 10+10}&#8217;<br \/>\n20<br \/>\n[root@shell \/server\/scripts]$ awk &#8216;BEGIN{print 10-10}&#8217;<br \/>\n0<br \/>\n[root@shell \/server\/scripts]$ awk &#8216;BEGIN{print 10+100\/2}&#8217;<br \/>\n60<br \/>\n[root@shell \/server\/scripts]$ awk &#8216;BEGIN{print 10+100\/2*4}&#8217;<br \/>\n210<\/p>\n<p>[root@shell \/server\/scripts]$ echo 10 20|awk &#8216;{print $1+$2}&#8217;<br \/>\n30<\/p>\n<h3>python \u76f4\u63a5\u8fd0\u7b97<\/h3>\n<p>[root@shell \/server\/scripts]$ python<br \/>\nPython 2.7.5 (default, Apr 2 2020, 13:16:51)<br \/>\n[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2<br \/>\nType &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br \/>\n&gt;&gt;&gt; 1+1<br \/>\n2<br \/>\n&gt;&gt;&gt; 10*10<br \/>\n100<br \/>\n&gt;&gt;&gt; 1.5*10<br \/>\n15.0<br \/>\n&gt;&gt;&gt; 100\/2.5<br \/>\n40.0<br \/>\n&gt;&gt;&gt; 10+10*10\/2<br \/>\n60<\/p>\n<h2>\u8868\u793a\u7b26<\/h2>\n<p>-eq\uff1a\u7b49\u4e8e<\/p>\n<p>-ne\uff1a\u4e0d\u7b49\u4e8e<\/p>\n<p>-lt\uff1a\u5c0f\u4e8e<\/p>\n<p>-le\uff1a\u5c0f\u4e8e\u7b49\u4e8e<\/p>\n<p>-gt\uff1a\u5927\u4e8e<\/p>\n<p>-ge\uff1a\u5927\u4e8e\u7b49\u4e8e<\/p>\n<h2>\u5728Shell\u811a\u672c\u4e2d\uff0c\u5e38\u7528\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/h2>\n<p>\u903b\u8f91\u4e0e\uff1a&amp;&amp;<\/p>\n<p>\u7528\u6cd5\uff1acommand1 &amp;&amp; command2<\/p>\n<p>\u89e3\u91ca\uff1a\u8868\u793a\u5f53\u00a0command1\u00a0\u6267\u884c\u6210\u529f\uff08\u8fd4\u56de\u72b6\u6001\u7801\u4e3a0\uff09\u65f6\uff0c\u624d\u4f1a\u6267\u884c\u00a0command2\u3002<\/p>\n<p>\u903b\u8f91\u6216\uff1a||<\/p>\n<p>\u7528\u6cd5\uff1acommand1 || command2<\/p>\n<p>\u89e3\u91ca\uff1a\u8868\u793a\u5f53\u00a0command1\u00a0\u6267\u884c\u5931\u8d25\uff08\u8fd4\u56de\u72b6\u6001\u7801\u975e0\uff09\u65f6\uff0c\u624d\u4f1a\u6267\u884c\u00a0command2\u3002<\/p>\n<p>\u903b\u8f91\u975e\uff1a!<\/p>\n<p>\u7528\u6cd5\uff1a!command<\/p>\n<p>\u89e3\u91ca\uff1a\u8868\u793a\u5bf9\u00a0command\u00a0\u7684\u6267\u884c\u7ed3\u679c\u8fdb\u884c\u53d6\u53cd\uff0c\u5373\u5982\u679c\u00a0command\u00a0\u6267\u884c\u6210\u529f\uff0c\u5219\u8fd4\u56de\u72b6\u6001\u7801\u4e3a0\uff0c\u5426\u5219\u8fd4\u56de\u72b6\u6001\u7801\u975e0<\/p>\n<h4>\u5728Shell\u4e2d\uff0cor\u00a0\u548c\u00a0and\u00a0\u4e5f\u53ef\u4ee5\u4f7f\u7528\u00a0-o\u00a0\u548c\u00a0-a\u00a0\u6765\u8868\u793a\u3002\u8fd9\u4e9b\u90fd\u662f\u903b\u8f91\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\u8fde\u63a5\u591a\u4e2a\u6761\u4ef6\u3002<\/h4>\n<p>-o\u00a0\u8868\u793a\u903b\u8f91\u6216\uff0c\u5b83\u8fde\u63a5\u7684\u4e24\u4e2a\u6761\u4ef6\u4e2d\u53ea\u8981\u6709\u4e00\u4e2a\u4e3a\u771f\uff0c\u6574\u4e2a\u6761\u4ef6\u5c31\u4e3a\u771f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>if [ \"$a\" -eq 1 -o \"$b\" -eq 2 ]\r\nthen\r\n  echo \"a is 1 or b is 2\"\r\nfi\r\n<\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u5982\u679c\u00a0$a\u00a0\u7684\u503c\u7b49\u4e8e 1 \u6216\u8005\u00a0$b\u00a0\u7684\u503c\u7b49\u4e8e 2\uff0c\u90a3\u4e48\u6574\u4e2a\u6761\u4ef6\u5c31\u4f1a\u4e3a\u771f\uff0c\u6267\u884c\u00a0echo\u00a0\u8bed\u53e5\u3002<\/p>\n<p>-a\u00a0\u8868\u793a\u903b\u8f91\u4e0e\uff0c\u5b83\u8fde\u63a5\u7684\u4e24\u4e2a\u6761\u4ef6\u90fd\u5fc5\u987b\u4e3a\u771f\uff0c\u6574\u4e2a\u6761\u4ef6\u624d\u4e3a\u771f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>if [ \"$a\" -eq 1 -a \"$b\" -eq 2 ]\r\nthen\r\n  echo \"a is 1 and b is 2\"\r\nfi\r\n<\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u5982\u679c\u00a0$a\u00a0\u7684\u503c\u7b49\u4e8e 1 \u4e14\u00a0$b\u00a0\u7684\u503c\u7b49\u4e8e 2\uff0c\u90a3\u4e48\u6574\u4e2a\u6761\u4ef6\u5c31\u4f1a\u4e3a\u771f\uff0c\u6267\u884c\u00a0echo\u00a0\u8bed\u53e5\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c-o\u00a0\u548c\u00a0-a\u00a0\u7684\u4f18\u5148\u7ea7\u6bd4\u8f83\u4f4e\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u65f6\u9700\u8981\u52a0\u4e0a\u62ec\u53f7\uff0c\u4ee5\u786e\u4fdd\u6761\u4ef6\u7684\u4f18\u5148\u7ea7\u6b63\u786e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>if [ \"$a\" -eq 1 -o \"$b\" -eq 2 ] &amp;&amp; [ \"$c\" -eq 3 ]\r\nthen\r\n  echo \"a is 1 or b is 2, and c is 3\"\r\nfi\r\n<\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c-o\u00a0\u7684\u4f18\u5148\u7ea7\u6bd4\u00a0-a\u00a0\u4f4e\uff0c\u56e0\u6b64\u9700\u8981\u52a0\u4e0a\u62ec\u53f7\uff0c\u4ee5\u786e\u4fdd\u5148\u6267\u884c\u00a0-o\u00a0\u8fde\u63a5\u7684\u4e24\u4e2a\u6761\u4ef6\uff0c\u518d\u6267\u884c\u00a0-a\u00a0\u8fde\u63a5\u7684\u6761\u4ef6\u3002<\/p>\n<h2>\u901a\u914d\u7b26\u7528\u4e8e\u5339\u914d\u6587\u4ef6\u540d\u6216\u8def\u5f84\u540d\u4e2d\u7684\u5b57\u7b26\u3002\u5e38\u7528\u7684\u901a\u914d\u7b26\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/h2>\n<p>*\uff1a\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n<p>\u4f8b\u5982\uff1a*.txt\u00a0\u53ef\u4ee5\u5339\u914d\u6240\u6709\u4ee5\u00a0.txt\u00a0\u7ed3\u5c3e\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>?\uff1a\u5339\u914d\u5355\u4e2a\u4efb\u610f\u5b57\u7b26\u3002<\/p>\n<p>\u4f8b\u5982\uff1afile?.txt\u00a0\u53ef\u4ee5\u5339\u914d\u00a0file1.txt\u3001file2.txt\u00a0\u7b49\u3002<\/p>\n<p>[]\uff1a\u5339\u914d\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5b57\u7b26\u3002<\/p>\n<p>\u4f8b\u5982\uff1a[abc]\u00a0\u53ef\u4ee5\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u4e3a a\u3001b \u6216 c \u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>{}\uff1a\u7528\u4e8e\u751f\u6210\u5b57\u7b26\u4e32\u5e8f\u5217\u3002<\/p>\n<p>\u4f8b\u5982\uff1a{apple,banana,orange}\u00a0\u53ef\u4ee5\u5339\u914d\u00a0apple\u3001banana\u00a0\u6216\u00a0orange\u3002<\/p>\n<p>\u8fd9\u4e9b\u901a\u914d\u7b26\u53ef\u4ee5\u5728Shell\u4e2d\u7528\u4e8e\u6587\u4ef6\u540d\u7684\u5339\u914d\u548c\u66ff\u6362\uff0c\u5e2e\u52a9\u6211\u4eec\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c\u548c\u6279\u91cf\u5904\u7406\u3002<\/p>\n<h2>test<\/h2>\n<h4>\u6587\u4ef6\u5c5e\u6027\u6d4b\u8bd5<\/h4>\n<p>-e file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728<br \/>\n-f file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u4e3a\u5e38\u89c4\u6587\u4ef6<br \/>\n-d file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u4e3a\u76ee\u5f55<br \/>\n-r file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u53ef\u8bfb<br \/>\n-w file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u53ef\u5199<br \/>\n-x file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u53ef\u6267\u884c<br \/>\n-s file\uff1a\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u975e\u7a7a<br \/>\n-O file\uff1a\u68c0\u67e5\u5f53\u524d\u7528\u6237\u662f\u5426\u662f\u6587\u4ef6\u7684\u6240\u6709\u8005<br \/>\n-G file\uff1a\u68c0\u67e5\u6587\u4ef6\u7684\u6240\u5c5e\u7ec4\u662f\u5426\u4e0e\u5f53\u524d\u7528\u6237\u76f8\u540c<br \/>\nfile1 -nt file2\uff1a\u68c0\u67e5 file1 \u662f\u5426\u6bd4 file2 \u65b0<br \/>\nfile1 -ot file2\uff1a\u68c0\u67e5 file1 \u662f\u5426\u6bd4 file2 \u65e7<\/p>\n<h4>\u5b57\u7b26\u4e32\u6bd4\u8f83<\/h4>\n<p>-z string\uff1a\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a<br \/>\n-n string\uff1a\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u975e\u7a7a<br \/>\nstring1 = string2\uff1a\u68c0\u67e5\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49<br \/>\nstring1 != string2\uff1a\u68c0\u67e5\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u4e0d\u76f8\u7b49<\/p>\n<h4>\u6570\u503c\u6bd4\u8f83<\/h4>\n<p>int1 -eq int2\uff1a\u68c0\u67e5\u4e24\u4e2a\u6574\u6570\u662f\u5426\u76f8\u7b49<br \/>\nint1 -ne int2\uff1a\u68c0\u67e5\u4e24\u4e2a\u6574\u6570\u662f\u5426\u4e0d\u76f8\u7b49<br \/>\nint1 -gt int2\uff1a\u68c0\u67e5 int1 \u662f\u5426\u5927\u4e8e int2<br \/>\nint1 -ge int2\uff1a\u68c0\u67e5 int1 \u662f\u5426\u5927\u4e8e\u7b49\u4e8e int2<br \/>\nint1 -lt int2\uff1a\u68c0\u67e5 int1 \u662f\u5426\u5c0f\u4e8e int2<br \/>\nint1 -le int2\uff1a\u68c0\u67e5 int1 \u662f\u5426\u5c0f\u4e8e\u7b49\u4e8e int2<\/p>\n<p>\u8fd9\u4e9b\u53c2\u6570\u53ef\u4ee5\u7528\u4e8e\u5728 Shell \u811a\u672c\u4e2d\u8fdb\u884c\u6761\u4ef6\u6d4b\u8bd5\u3002\u4f8b\u5982\uff1a<\/p>\n<p>if [ -f &#8220;$file&#8221; -a -r &#8220;$file&#8221; ];<br \/>\nthen echo &#8220;\u6587\u4ef6 $file \u5b58\u5728\u4e14\u53ef\u8bfb&#8221;<br \/>\nfi<\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c-f &#8220;$file&#8221;\u00a0\u7528\u4e8e\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u4e3a\u5e38\u89c4\u6587\u4ef6\uff0c-r &#8220;$file&#8221;\u00a0\u7528\u4e8e\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u53ef\u8bfb\u3002\u5982\u679c\u8fd9\u4e24\u4e2a\u6761\u4ef6\u90fd\u6ee1\u8db3\uff0c\u5219\u6253\u5370\u51fa\u6587\u4ef6\u5b58\u5728\u4e14\u53ef\u8bfb\u7684\u4fe1\u606f\u3002<\/p>\n<h4>test\u7684\u4f7f\u7528<\/h4>\n<p>[root@shell \/server\/scripts]$ test 10 -eq 10 &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u6210\u7acb<br \/>\n[root@shell \/server\/scripts]$ test 100 -eq 10 &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u4e0d\u6210\u7acb<br \/>\n[root@shell \/server\/scripts]$ test 100 -ne 10 &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u6210\u7acb<\/p>\n<h4>\u6bd4\u8f83\u5927\u5c0f<\/h4>\n<p>[root@shell \/server\/scripts]$ [ 10 -gt 5 ] &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u6210\u7acb<br \/>\n[root@shell \/server\/scripts]$ [ 10 -ne 5 ] &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u6210\u7acb<br \/>\n[root@shell \/server\/scripts]$ [ 10 -lt 5 ] &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u4e0d\u6210\u7acb<br \/>\n[root@shell \/server\/scripts]$ [ 10 -gt 10 ] &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u4e0d\u6210\u7acb<br \/>\n[root@shell \/server\/scripts]$ [ 10 -ge 10 ] &amp;&amp; echo \u6210\u7acb || echo \u4e0d\u6210\u7acb<br \/>\n\u6210\u7acb<\/p>\n<h4>\u5224\u65ad\u4f20\u5165\u7684\u53c2\u6570\u5fc5\u987b\u4e3a\u6574\u6570 \u5426\u5219\u9000\u51fa\u811a\u672c<\/h4>\n<p>[root@shell \/server\/scripts]$ cat count.sh<br \/>\n#!\/bin\/bash<br \/>\necho $1+$2=$[$1+$2]<br \/>\necho $1-$2=$[$1-$2]<br \/>\necho $1*$2=$[$1*$2]<br \/>\necho $1\/$2=$[$1\/$2]<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221;<br \/>\nnum1=$1<br \/>\nnum2=$2<br \/>\n#echo $num1+$num2=$[$num1+$num2]<br \/>\n#echo $num1-$num2=$[$num1-$num2]<br \/>\n#echo $num1*$num2=$[$num1*$num2]<br \/>\n#echo $num1\/$num2=$[$num1\/$num2]<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u4e24\u4e2a\u6574\u6570: &#8221; num1 num2<br \/>\nexpr $num1 + $num2 &amp;&gt;\/dev\/null<br \/>\n[ $? -ne 0 ] &amp;&amp; echo &#8220;\u4f60\u8f93\u5165\u7684\u4e0d\u662f\u6574\u6570&#8221; &amp;&amp; exit<br \/>\necho $num1+$num2=$[$num1+$num2]<br \/>\necho $num1-$num2=$[$num1-$num2]<br \/>\necho $num1*$num2=$[$num1*$num2]<br \/>\necho $num1\/$num2=$[$num1\/$num2]<br \/>\n[root@shell \/server\/scripts]$ sh count.sh 10 20<br \/>\n10+20=30<br \/>\n10-20=-10<br \/>\n10*20=200<br \/>\n10\/20=0<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n10+20=30<br \/>\n10-20=-10<br \/>\n10*20=200<br \/>\n10\/20=0<br \/>\n\u8bf7\u8f93\u5165\u4e24\u4e2a\u6574\u6570: 10 20<br \/>\n10+20=30<br \/>\n10-20=-10<br \/>\n10*20=200<br \/>\n10\/20=0<\/p>\n<h4>\u5faa\u73af\uff08\u6b63\u786e\u5219\u9000\u51fa\uff0c\u9519\u8bef\u5219\u7ee7\u7eed\uff09<\/h4>\n<p>[root@shell \/server\/scripts]$ cat count1.sh<br \/>\n#!\/bin\/bash<br \/>\necho $1+$2=$[$1+$2]<br \/>\necho $1-$2=$[$1-$2]<br \/>\necho $1*$2=$[$1*$2]<br \/>\necho $1\/$2=$[$1\/$2]<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221;<br \/>\nnum1=$1<br \/>\nnum2=$2<br \/>\necho $num1+$num2=$[$num1+$num2]<br \/>\necho $num1-$num2=$[$num1-$num2]<br \/>\necho $num1*$num2=$[$num1*$num2]<br \/>\necho $num1\/$num2=$[$num1\/$num2]<br \/>\nwhile true<br \/>\ndo<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u4e24\u4e2a\u6574\u6570: &#8221; num1 num2<br \/>\nexpr $num1 + $num2 &amp;&gt;\/dev\/null<br \/>\n[ $? -ne 0 ] &amp;&amp; echo &#8220;\u4f60\u8f93\u5165\u7684\u4e0d\u662f\u6574\u6570&#8221; &amp;&amp; continue<br \/>\necho $num1+$num2=$[$num1+$num2]<br \/>\necho $num1-$num2=$[$num1-$num2]<br \/>\necho $num1*$num2=$[$num1*$num2]<br \/>\necho $num1\/$num2=$[$num1\/$num2]<br \/>\nbreak<\/p>\n<p>done<br \/>\n[root@shell \/server\/scripts]$ sh count1.sh 10 20<br \/>\n10+20=30<br \/>\n10-20=-10<br \/>\n10*20=200<br \/>\n10\/20=0<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n10+20=30<br \/>\n10-20=-10<br \/>\n10*20=200<br \/>\n10\/20=0<br \/>\n\u8bf7\u8f93\u5165\u4e24\u4e2a\u6574\u6570: 12 12.1<br \/>\n\u4f60\u8f93\u5165\u7684\u4e0d\u662f\u6574\u6570<br \/>\n\u8bf7\u8f93\u5165\u4e24\u4e2a\u6574\u6570: 12 12<br \/>\n12+12=24<br \/>\n12-12=0<br \/>\n12*12=144<br \/>\n12\/12=1<\/p>\n<h4>\u7b2c\u4e8c\u79cd<\/h4>\n<p>[root@shell \/server\/scripts]$ cat count2.sh<br \/>\n#!\/bin\/bash<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u7b2c\u4e00\u4e2a\u6574\u6570\uff1a&#8221; a<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u52a0\u51cf\u4e58\u9664\u6216\u5176\u4ed6\u8fd0\u7b97\u7b26\u53f7\uff1a&#8221; c<br \/>\nread -p &#8220;\u8bf7\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6574\u6570\uff1a&#8221; b<br \/>\nexpr $a + $b &amp;&gt;\/dev\/null<br \/>\nif [ $? -eq 0 ];then<br \/>\nd=$(awk &#8216;BEGIN{print &#8216;$a&#8217; &#8216;$c&#8217; &#8216;$b&#8217;}&#8217;)<br \/>\necho &#8220;\u4f60\u8981\u8fd0\u7b97\u7684\u662f$a$c$b=$d&#8221;<br \/>\nelse<br \/>\necho &#8220;\u4f60\u8f93\u5165\u7684\u4e0d\u662f\u6574\u6570\uff0c\u6216\u7279\u6b8a\u5b57\u7b26\u672a\u8f6c\u4e49&#8221;<br \/>\nfi<\/p>\n<h4>\u7edf\u8ba1\u5185\u5b58\u4f7f\u7528\u7387 \u4f7f\u7528\u7387\u8d85\u8fc7\u767e\u5206\u4e4b5 \u5219\u53d1\u9001\u90ae\u7bb1\u62a5\u8b66 \u5426\u5219\u8f93\u51fa\u63d0\u793a\u4f7f\u7528\u6b63\u5e38 \u8f93\u51fa\u5f53\u524d\u5185\u5b58\u4f7f\u7528\u7387<br \/>\n\u5185\u5b58\u767e\u5206\u6bd4\u8ba1\u7b97\u65b9\u5f0f: \u5df2\u4f7f\u7528\u7684\u9664\u603b\u7684\u4e58100<\/h4>\n<p>[root@shell \/server\/scripts]$ cat free.sh<br \/>\n#!\/bin\/sh<br \/>\nMem_use=`free|awk &#8216;NR==2{print $3\/$2*100}&#8217;`<br \/>\n[ ${Mem_use%.*} -gt 5 ] &amp;&amp; echo -e &#8220;Subject: free\\n\\n${Mem_use%.*}&#8221; | sendmail -v xxxxxxxxx@163.com || echo ${Mem_use}%<\/p>\n<p>#[ ${Mem_use%.*} -gt 5 ] &amp;&amp; echo &#8220;${Mem_use%.*}&#8221; | mail -s &#8220;free&#8221; xxxxxxxx@163.com || echo ${Mem_use}%<\/p>\n<h4>\u7edf\u8ba11\u5206\u949f\u5185\u7cfb\u7edf\u7684\u5e73\u5747\u8d1f\u8f7d \u8d85\u8fc71\u5219\u53d1\u9001\u90ae\u4ef6 \u5426\u5219\u63d0\u793a\u6b63\u5e38<\/h4>\n<p>[root@shell \/server\/scripts]$ cat upload.sh<br \/>\n#!\/bin\/sh<br \/>\nuse_load=`uptime|awk &#8216;{print $(NF-2)}&#8217;`<br \/>\n[ ${use_load%.*} -gt 1 ] &amp;&amp; echo -e &#8220;Subject: upload\\n\\n${use_load%.*}&#8221; | sendmail -v xxxxxxxxxx@163.com || echo &#8220;${use_load%,}%&#8221;<\/p>\n<p>[root@shell ~]$ ulimit -HSn 65535<\/p>\n<p>\u8fd9\u6761\u547d\u4ee4\u7528\u4e8e\u8bbe\u7f6e\u5f53\u524d\u7528\u6237\u7684\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u4e3a65535\u3002\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u64cd\u4f5c\u7cfb\u7edf\u7528\u6765\u6807\u8bc6\u5df2\u88ab\u6253\u5f00\u6587\u4ef6\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u901a\u8fc7\u8bbe\u7f6e\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\uff0c\u53ef\u4ee5\u63a7\u5236\u7528\u6237\u80fd\u591f\u540c\u65f6\u6253\u5f00\u7684\u6587\u4ef6\u6570\u91cf\u3002<\/p>\n<p>\u5177\u4f53\u800c\u8a00\uff0culimit -HSn 65535\u4e2d\uff1a<\/p>\n<p>ulimit\u00a0\u662f\u4e00\u4e2a\u7528\u4e8e\u8bbe\u7f6e\u6216\u663e\u793a\u7528\u6237\u8fdb\u7a0b\u8d44\u6e90\u9650\u5236\u7684\u547d\u4ee4\u3002<br \/>\n-H\u00a0\u8868\u793a\u8bbe\u7f6e\u6216\u663e\u793a\u786c\u9650\u5236\uff0c\u5373\u7528\u6237\u80fd\u591f\u8bbe\u7f6e\u7684\u6700\u5927\u503c\u3002<br \/>\n-S\u00a0\u8868\u793a\u8bbe\u7f6e\u6216\u663e\u793a\u8f6f\u9650\u5236\uff0c\u5373\u7528\u6237\u5f53\u524d\u5b9e\u9645\u53ef\u7528\u7684\u6700\u5927\u503c\u3002<br \/>\nn\u00a0\u8868\u793a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6570\u91cf\u3002<br \/>\n65535\u00a0\u662f\u8bbe\u5b9a\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u3002<\/p>\n<p>\u8fd9\u6761\u547d\u4ee4\u7684\u4f5c\u7528\u662f\u5c06\u5f53\u524d\u7528\u6237\u7684\u8f6f\u9650\u5236\u548c\u786c\u9650\u5236\u90fd\u8bbe\u7f6e\u4e3a65535\uff0c\u5373\u7528\u6237\u53ef\u4ee5\u540c\u65f6\u6253\u5f00\u7684\u6587\u4ef6\u6570\u91cf\u6700\u5927\u4e3a65535\u3002<\/p>\n<p>[root@shell ~]$ ab -n200000 -c20000 http:\/\/127.0.0.1\/index.html<\/p>\n<h4>[[ ]]\u00a0\u662f Bash shell \u4e2d\u7684\u4e00\u79cd\u6761\u4ef6\u8bed\u53e5\uff0c\u7528\u4e8e\u6d4b\u8bd5\u6761\u4ef6\u662f\u5426\u6210\u7acb\u3002\u4e0e\u5355\u4e2a\u65b9\u62ec\u53f7\u00a0[ ]\u00a0\u4e0d\u540c\uff0c[[ ]]\u00a0\u652f\u6301\u66f4\u591a\u7684\u6761\u4ef6\u6d4b\u8bd5\u548c\u8bed\u6cd5\u3002<\/h4>\n<pre>[[ expression ]]\r\n<\/pre>\n<p>\u5176\u4e2d\u00a0expression\u00a0\u662f\u4e00\u4e2a\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u5305\u542b\u53d8\u91cf\u3001\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u8fd0\u7b97\u7b26\u7b49\u3002[[ ]]\u00a0\u4f1a\u5c06\u00a0expression\u00a0\u4e2d\u7684\u5185\u5bb9\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u8fdb\u884c\u89e3\u6790\u548c\u5224\u65ad\uff0c\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u6761\u4ef6\u6d4b\u8bd5\u6765\u5224\u65ad\u5176\u662f\u5426\u4e3a\u771f\u3002<\/p>\n<p>[[ ]]\u00a0\u652f\u6301\u7684\u6761\u4ef6\u6d4b\u8bd5\u5305\u62ec\uff1a<\/p>\n<p>\u5b57\u7b26\u4e32\u6bd4\u8f83\uff1a==\u3001!=\u3001=~\uff08\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\uff09<\/p>\n<p>\u6570\u503c\u6bd4\u8f83\uff1a-eq\u3001-ne\u3001-lt\u3001-le\u3001-gt\u3001-ge<\/p>\n<p>\u6587\u4ef6\u6d4b\u8bd5\uff1a-e\uff08\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff09\u3001-f\uff08\u662f\u5426\u4e3a\u6587\u4ef6\uff09\u3001-d\uff08\u662f\u5426\u4e3a\u76ee\u5f55\uff09\u3001-r\uff08\u662f\u5426\u53ef\u8bfb\uff09\u3001-w\uff08\u662f\u5426\u53ef\u5199\uff09\u3001-x\uff08\u662f\u5426\u53ef\u6267\u884c\uff09<\/p>\n<p>\u903b\u8f91\u8fd0\u7b97\uff1a&amp;&amp;\uff08\u903b\u8f91\u4e0e\uff09\u3001||\uff08\u903b\u8f91\u6216\uff09\u3001!\uff08\u903b\u8f91\u975e\uff09<\/p>\n<p>[[ ]]\u00a0\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u907f\u514d\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u7a7a\u683c\u6216\u7279\u6b8a\u5b57\u7b26\u65f6\u7684\u95ee\u9898\uff0c\u4ee5\u53ca\u5404\u79cd\u6761\u4ef6\u6d4b\u8bd5\u7684\u8bed\u6cd5\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u5728 Bash shell \u4e2d\uff0c\u63a8\u8350\u4f7f\u7528\u00a0[[ ]]\u00a0\u6765\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\u3002<\/p>\n<h3>[[]]\u7684\u4f7f\u7528<\/h3>\n<h4>\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\uff1a<\/h4>\n<pre>if [[ -z $var ]]; then\r\n    echo \"\u53d8\u91cf var \u4e3a\u7a7a\"\r\nfi\r\n<\/pre>\n<h4>\u5b57\u7b26\u4e32\u6bd4\u8f83\uff1a<\/h4>\n<pre>if [[ $str1 == $str2 ]]; then\r\n    echo \"str1 \u548c str2 \u76f8\u7b49\"\r\nfi\r\n<\/pre>\n<h4>\u6587\u4ef6\u5c5e\u6027\u68c0\u67e5\uff1a<\/h4>\n<pre>if [[ -f $file &amp;&amp; -r $file ]]; then\r\n    echo \"\u6587\u4ef6 $file \u5b58\u5728\u4e14\u53ef\u8bfb\"\r\nfi\r\n<\/pre>\n<h4>\u6570\u503c\u6bd4\u8f83\uff1a<\/h4>\n<pre>if [[ $num -gt 10 ]]; then\r\n    echo \"num \u5927\u4e8e 10\"\r\nfi\r\n<\/pre>\n<h4>\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\uff1a<\/h4>\n<pre>if [[ $str =~ ^[0-9]+$ ]]; then\r\n    echo \"str \u662f\u4e00\u4e2a\u7eaf\u6570\u5b57\u5b57\u7b26\u4e32\"\r\nfi\r\n<\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u00a0[[\u00a0\u548c\u00a0]]\u00a0\u4e2d\uff0c\u53d8\u91cf\u4e0d\u9700\u8981\u4f7f\u7528\u5f15\u53f7\u62ec\u8d77\u6765\uff0c\u800c\u4e14\u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c\u5b57\u7b26\u4e32\u6bd4\u8f83\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7b49\u64cd\u4f5c\u3002\u6b64\u5916\uff0c[[\u00a0\u548c\u00a0]]\u00a0\u4e5f\u652f\u6301\u903b\u8f91\u8fd0\u7b97\u7b26\uff08&amp;&amp;\u3001||\u3001!\uff09\u6765\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6<\/p>\n<h4>\u811a\u672c<\/h4>\n<p>[root@shell \/server\/scripts]$ cat xshell.sh<br \/>\necho \u5f53\u524d\u7684\u4e3b\u673a\u540d\u79f0\u4e3a: `hostname`<br \/>\necho \u5f53\u524d\u7684ip\u5730\u5740\u4e3a: `hostname -I | awk &#8216;{print $1}&#8217;`<br \/>\necho \u5f53\u524d\u7684\u5916\u7f51ip\u4e3a: `curl cip.cc -s | awk &#8216;\/IP\/{print $3}&#8217;`<br \/>\necho \u5f53\u524d\u7684\u865a\u62df\u5e73\u53f0\u662f: `hostnamectl | awk -F &#8216;:&#8217; &#8216;NR==6{print $2}&#8217;`<br \/>\necho \u5f53\u524d\u7684\u7cfb\u7edf\u7248\u672c\u662f: `hostnamectl | awk -F &#8216;:&#8217; &#8216;NR==7{print $2}&#8217;`<br \/>\necho \u5f53\u524d\u7684cpu\u7684\u4f7f\u7528\u7387: `top -n 1 -b | awk &#8216;\/%Cpu\/{print $2&#8243;%&#8221;}&#8217;`<br \/>\necho \u5f53\u524d\u7684\u5185\u5b58\u7684\u4f7f\u7528\u7387: `free | awk &#8216;\/Mem\/{print $3\/$2*100&#8243;%&#8221;}&#8217;`<br \/>\necho \u5f53\u524d\u7684\u78c1\u76d8\u7684\u4f7f\u7528\u7387: `df -h | awk &#8216;NR==6{print $5}&#8217;`<br \/>\necho \u5f53\u524d\u7684\u5185\u6838\u7248\u672c\u662f: `hostnamectl | awk -F &#8216;:&#8217; &#8216;NR==9{print $2}&#8217;`<\/p>\n<p>[root@shell \/server\/scripts]$ sh xshell.sh<br \/>\n\u5f53\u524d\u7684\u4e3b\u673a\u540d\u79f0\u4e3a: shell<br \/>\n\u5f53\u524d\u7684ip\u5730\u5740\u4e3a: 10.0.0.65<br \/>\n\u5f53\u524d\u7684\u5916\u7f51ip\u4e3a: 153.142.45.122<br \/>\n\u5f53\u524d\u7684\u865a\u62df\u5e73\u53f0\u662f: vmware<br \/>\n\u5f53\u524d\u7684\u7cfb\u7edf\u7248\u672c\u662f: CentOS Linux 7 (Core)<br \/>\n\u5f53\u524d\u7684cpu\u7684\u4f7f\u7528\u7387: 0.0%<br \/>\n\u5f53\u524d\u7684\u5185\u5b58\u7684\u4f7f\u7528\u7387: 8.10687%<br \/>\n\u5f53\u524d\u7684\u78c1\u76d8\u7684\u4f7f\u7528\u7387: 5%<br \/>\n\u5f53\u524d\u7684\u5185\u6838\u7248\u672c\u662f: Linux 3.10.0-1127.el7.x86_64<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u52a0export\u548c\u4e0d\u52a0\u7684\u533a\u522b \u5728Shell\u811a\u672c\u4e2d\uff0c`export`\u547d\u4ee4\u7528\u4e8e\u5c06\u53d8\u91cf\u5bfc\u51fa\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u4f7f\u5176\u5728\u811a\u672c\u4e4b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[25],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/1247"}],"collection":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1247"}],"version-history":[{"count":12,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/1247\/revisions"}],"predecessor-version":[{"id":1276,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/1247\/revisions\/1276"}],"wp:attachment":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}