\r\n[14:05:26 ~]#set +x #\u5173\u95ed\u547d\u4ee4\u8f93\u51fa\u6a21\u5f0f\r\n[14:05:27 ~]echo ${#IFS}\r\n3\r\n<\/pre>\n\u770b\u6765\u6709\u4e09\u4e2a\u5b57\u7b26\u5b58\u50a8\u5728IFS\u91cc\u9762\uff0c\u90a3\u4e48\u6328\u4e2a\u6328\u4e2a\u7684\u67e5\u770b\u4e0b.<\/p>\n
\r\n[14:08:10 ~]#set -x #\u5f00\u542f\u547d\u4ee4\u8f93\u51fa\u6a21\u5f0f\r\n[14:08:10 ~]#echo -n ${IFS:0:1}\r\n+ echo -n\r\n[14:08:11 ~]#echo -n "${IFS:0:1}"\r\n+ echo -n ' '\r\n [14:08:12 ~]#\r\n<\/pre>\n\u5230\u8fd9\u91cc\uff0c\u5927\u5bb6\u5e94\u8be5\u660e\u767d\u4e86\uff0c\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5b58\u50a8\u7684\u662f\u7a7a\u683c\uff0clinux\u9ed8\u8ba4\u5427\u7a7a\u683c\u4f5c\u4e3a\u5206\u9694\u7b26.
\n\u53ef\u80fd\u8fd8\u6709\u540c\u5b66\u4f1a\u6709\u7591\u95ee\uff0c\u52a0\u53cc\u5f15\u53f7\uff0c\u548c\u4e0d\u52a0\u53cc\u5f15\u53f7\uff0c\u4e3a\u4ec0\u4e48\u8f93\u51fa\u4e0d\u540c\uff0c\u8fd9\u91cc\u7b80\u5355\u8bf4\u4e00\u4e0b(\u540e\u9762\u4f1a\u66f4\u8be6\u7ec6\u7684\u8bf4\u660e)\uff0c ” <\/span>\u5728linux\u4e2d\u5177\u6709\u975e\u5e38\u7279\u522b\u7684\u610f\u4e49\uff0c\u901a\u5e38\u88ab\u79f0\u547c\u4e3a\u5f3a\u5236\u5f15\u7528\u7b26<\/span>.\u5373\u88ab\u53cc\u5f15\u53f7\u5305\u62ec\u7684\u5185\u5bb9\uff0c\u5c31\u4e00\u5b9a\u4f1a\u88ab\u89e3\u91ca\uff0c\u5305\u62ec\u7a7a\u767d\uff0c\u6240\u4ee5\u5373\u4f7f${IFS:0:1}\u662f\u4e00\u4e2a\u7a7a\u683c\uff0cecho \u8fd8\u662f\u4f1a\u8f93\u51fa\u8fd9\u4e2a\u7a7a\u683c(\u7b2c\u516d\u884c)!
\n\u90a3\u4e48\u63a5\u4e0b\u6765\u5c31\u7b80\u5355\u591a\u4e86.<\/p>\n\r\n[14:25:52 ~]#echo -n ${IFS:1:1}\r\n+ echo -n\r\n[14:25:55 ~]#echo -n "${IFS:1:1}"\r\n+ echo -n '\t'\r\n\t[14:25:59 ~]#\r\n<\/pre>\n\u7b2c\u4e8c\u4e2a\u662f\u5236\u8868\u7b26\\t<\/span>\uff0c\u4f5c\u4e3alinux\u9ed8\u8ba4\u7684\u7b2c\u4e8c\u4e2a\u5206\u9694\u7b26.<\/p>\n\r\n[14:27:23 ~]#echo -n ${IFS:2:1}\r\n+ echo -n\r\n[14:34:38 ~]#echo -n "${IFS:2:1}"\r\n+ echo -n '\r\n'\r\n\r\n[14:34:42 ~]#\r\n<\/pre>\n\u7b2c\u4e09\u4e2a\u662f\u6362\u884c\u7b26\\n<\/span>\uff0c\u4f5c\u4e3alinux\u9ed8\u8ba4\u7684\u7b2c\u4e09\u4e2a\u5206\u9694\u7b26.
\n\u8bb2\u89e3\u5206\u9694\u7b26\u662f\u4e3a\u4e86\u8ba9\u4f60\u8fdb\u4e00\u6b65\u4e86\u89e3bash\u5de5\u4f5c\u7684\u673a\u5236.\u5e2e\u52a9\u4f60\u7406\u89e3\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837\u7684\u8bed\u53e5.<\/p>\n\r\n#example.sh\r\narray=(a b c)\r\nfor i in "${arrary[*]}";do\r\n echo $i\r\ndone\r\nfor j in ${array[*]};do\r\n echo $j\r\ndone\r\n<\/pre>\n*\u5176\u5b9e\u5728\u4f7f\u7528\u6570\u7ec4\u4e2d\uff0c\u5982\u679c\u67d0\u4e00\u4e2a\u6210\u5458\u7684\u5185\u5bb9\u5305\u542b\u4e86\u5206\u9694\u7b26\uff0c\u90a3\u4e48\u5728\u4f7f\u7528${array[*]}\u5f80\u5f80\u4e0d\u662f\u4f60\u60f3\u8981\u7684\u7ed3\u679c.\u800c${array[@]}\u5374\u4f1a\u65b9\u4fbf\u7684\u591a.<\/span><\/p>\n\u4e0b\u9762\u6765\u4e86\u89e3bash\u7684\u51e0\u4e2a\u7279\u6b8a\u5b57\u7b26,\u5305\u62ec“<\/span>\uff0c‘<\/span>\uff0c`<\/span>\u3002
\n\u53cc\u5f15\u53f7“<\/span>\u5728shell\u4e2d\u4f7f\u7528\u7684\u5f88\u591a\uff0c\u7136\u800c\u80fd\u591f\u719f\u7ec3\u4f7f\u7528\u7684\u4eba\u5374\u4e0d\u591a.
\n\u56de\u987e\u4e0b\u53cc\u5f15\u53f7\u5728shell\u811a\u672c\u4e2d\u7684\u4f7f\u7528
\n\u8d4b\u503c\u53d8\u91cf,\u5f53\u53d8\u91cf\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff0c\u6bd4\u5982\u7a7a\u767d\u5b57\u7b26\u6216\u8005\u9700\u8981\u4f7f\u7528\u5f15\u7528\u53d8\u91cf\u7684\u65f6\u5019<\/p>\n\r\nvar1="hello world!" #\u8bf7\u6ce8\u610f\u8fd9\u6761\u8d4b\u503c\u8bed\u53e5\r\nvar2="welcome to blog.weskiller.com , $var1"\r\n<\/pre>\n\u4f7f\u7528grep awk sed\u547d\u4ee4<\/p>\n
\r\necho $var2|grep "hello world"\r\necho $var2|sed "s\/blog\/www\/"\r\necho $var2|awk "{print $3}"\r\n<\/pre>\n=V=\uff0c\u597d\u50cf\u51fa\u4e86\u4ec0\u4e48\u95ee\u9898~. \u5728\u7ed9var1\u8d4b\u503c\u7684\u65f6\u5019\u53d1\u751f\u4e86\u610f\u60f3\u4e0d\u5230\u7684\u4e8b\u60c5.<\/p>\n
\r\nvar1="hello world!"\r\n-bash: !": event not found\r\n<\/pre>\n\u8fd9\u662f\u4ec0\u4e48\u9b3c?
\n\u65b0\u624b\u4e00\u5b9a\u5728\u8fd9\u91cc\u61f5\u903c\u4e86\uff0c\u5176\u5b9e\u5728\u4ea4\u4e92\u5f0f\u7684shell\u4e2d!<\/span>\u4f1a\u88ab\u8f6c\u4e49\u4e3ahistory\uff0c\u5c31\u50cf\u4e0b\u9762\u6f14\u793a\u7684\u4e00\u6837\uff0c\u5176\u5b9e\u5728\u975e\u4ea4\u4e92\u7684shell\u4e2d\uff0c\u8fd9\u4e2a\u529f\u80fd\u4f1a\u88ab\u7981\u7528.<\/p>\n\r\n[15:41:18 ~\/scripts]#history -c\r\n[15:41:21 ~\/scripts]#ls\r\nbackup.sh clear_log.sh test.sh\r\n[15:41:22 ~\/scripts]#echo\r\n\r\n[15:41:35 ~\/scripts]#history 1\r\n 3 history 1\r\n[15:41:41 ~\/scripts]#!-1\r\nhistory 1\r\n 3 history 1\r\n[15:41:44 ~\/scripts]#\r\n<\/pre>\n\u6ca1\u9519\uff0c\u53cc\u5f15\u53f7\u5f3a\u5236\u8f6c\u4e49\u4e86!\uff0c\u800c\u5b9e\u9645\u4e0a\u5982\u679c\u4e0d\u7528\u53cc\u5f15\u53f7\u53cd\u800c\u8fbe\u5230\u4e86\u4f60\u60f3\u8981\u7684\u6548\u679c.<\/p>\n
\r\nvar1=hello\\ world! #\u8fd9\u91cc\u4f7f\u7528\u53cd\u659c\u7ebf\u6765\u8f6c\u4e49\u7a7a\u683c\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u88ab\u8ba4\u4e3a\u662f\u5206\u9694\u7b26\uff0c\u6240\u4ee5\u5728shell\u770b\u6765"hello world!"\u662f\u4e00\u4e2a\u6574\u4f53\r\necho $var1 \r\n<\/pre>\n\u5355\u5f15\u53f7‘<\/span>\u5728\u4f7f\u7528\u4e2d\u5f80\u5f80\u662f\u8981\u544a\u8bc9shell\uff0c\u4e0d\u8981\u4e71\u6539\u6211\u8f93\u51fa\u7684\u5185\u5bb9\uff0c\u5e38\u79f0\u547c\u4e3a\u5f31\u5f15\u7528\u7b26<\/span>\u3002
\n\u5c31\u50cf\u53cc\u5f15\u53f7\u9047\u5230\u7684\u60c5\u51b5\uff0c\u7528\u5355\u5f15\u53f7\u5c31\u53ef\u4ee5\u5b8c\u7f8e\u7684\u89e3\u51b3<\/p>\n\r\nvar1='hello world!'\r\n<\/pre>\n\u53cd\u5f15\u53f7`<\/span>\u53ef\u8c13\u662fshell\u811a\u672c\u8bed\u8a00\u7684\u7cbe\u534e\uff0c\u7528\u8fc7\u7684\u4eba\u90fd…\uff0c\u6211\u5e38\u79f0\u4e4b\u4e3a\u66ff\u6362\u7b26.
\n`command` \u4e2d\u7684\u547d\u4ee4\u4f1a\u88ab\u6267\u884c\u800c\u8f93\u51fa\u7ed3\u679c\u4f1a\u8fd4\u56de\uff0c\u8fd9\u4e2a\u548c$(command)\u5982\u51fa\u4e00\u8f99\uff0c\u552f\u4e00\u53ef\u80fd\u89c9\u5f97\u9057\u61be\u7684\u662f` `\u4e0d\u652f\u6301\u8c03\u5957\u4f7f\u7528\uff0c\u800c$()\u662f\u53ef\u4ee5\u591a\u6b21\u5d4c\u5957\u4f7f\u7528\u7684.
\n*\u5230\u73b0\u5728\u4e3a\u6b62\uff0c\u535a\u4e3b\u5c1a\u672a\u53d1\u73b0` `\u548c$()\u7684\u4f7f\u7528\u533a\u522b.
\n\u5728\u4f7f\u7528\u53cd\u5f15\u53f7\u7684\u65f6\u5019\u6ce8\u610f\u7684\u662f\u4e0d\u8981\u88ab\u5355\u5f15\u53f7\u5305\u62ec\uff0c\u540c\u65f6\u53cd\u5f15\u53f7\u5916\u7684\u53cc\u5f15\u53f7\u548c\u53cd\u5f15\u53f7\u5185\u7684\u53cc\u5f15\u53f7\u4e92\u4e0d\u5e72\u6270\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837<\/p>\n\r\ntimestamp="$(date --date "@$((`date --date "1 days ago" +%s`-2*3600))" +%F\\ %T)" #\u53d6\u5f97\u5f53\u524d\u65f6\u95f4\u95f4\u9694\u4e3a\u4e00\u5929\u4e24\u5c0f\u65f6\u7684\u65f6\u95f4\u6233\r\n<\/pre>\n\u8bb2\u4e86\u8fd9\u4e48\u591a\uff0c\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\u7684\u6548\u679c\u5982\u4f55?
\n\u6765\u770b\u770b\u5427<\/p>\n
\r\n#\u5b9a\u4e49\u65f6\u95f4\u6233\uff0c\u591a\u6b21\u590d\u7528date\u547d\u4ee4\r\ntoday="$(date --date @$(($(date --date "`date +%F`" +%s)-3600*8)) +%F\\ %T)"\r\ndelete_timestamp="$(date --date @$((`date --date "$today" +%s`+7*3600)) +%F\\ %T)"\r\n#\u5de7\u5999\u4f7f\u7528\u5355\u53cc\u5f15\u53f7,\u5728sed,awk\u4e2d\u63d2\u5165\u53d8\u91cf\r\npattern="`date +%F\\ %T`"\r\ngrep -P "$parttern" $log\r\nsed -i 's\/'"$pattern"'\/'"`date +%F`"'\/g' $log\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"Bourne-Again SHell\u662f\u7edd\u5927\u591a\u6570linux\u7cfb\u7edf\u4e0b\u9ed8\u8ba4\u7684shell\uff0c\u53ea\u8981\u6d89\u53calinux\u5e73\u53f0\u4e0a\u7684\u7814\u53d1 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[12],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-linux","category-shell","tag-12"],"_links":{"self":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":54,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":614,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/139\/revisions\/614"}],"wp:attachment":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}