{"id":35678,"date":"2023-02-14T17:37:44","date_gmt":"2023-02-14T09:37:44","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=35678"},"modified":"2023-02-14T17:37:44","modified_gmt":"2023-02-14T09:37:44","slug":"linux-bash-var","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-bash-var.html","title":{"rendered":"\u8be6\u89e3Linux bash\u53d8\u91cf"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/span><\/td>\nLinux\u4e2d\u7f16\u5199SHELL\u811a\u672c\u5fc5\u7136\u8981\u63a5\u89e6\u5230\u53d8\u91cf\uff0c\u672c\u6587\u5bf9bash\u4e2d\u4e0d\u540c\u7684\u53d8\u91cf\u7c7b\u578b\u8fdb\u884c\u4e00\u4e2a\u7b80\u8981\u8bf4\u660e<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"%e6%97%a0%e6%a0%87%e9%a2%98\"<\/p>\n

Bash\u53d8\u91cf\u7c7b\u578b<\/strong><\/span><\/span><\/div>\n
    \n
  1. \u672c\u5730\u53d8\u91cf<\/li>\n
  2. \u5c40\u90e8\u53d8\u91cf<\/li>\n
  3. \u73af\u5883\u53d8\u91cf<\/li>\n
  4. \u4f4d\u7f6e\u53d8\u91cf<\/li>\n
  5. \u7279\u6b8a\u53d8\u91cf\uff08\u5185\u7f6e\uff09<\/li>\n<\/ol>\n

    \u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\u5bf9\u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\u65f6\uff0c\"=\"\u4e24\u8fb9\u662f\u4e0d\u80fd\u6709\u7a7a\u767d\u7684\uff0c\u5426\u5219\u5c31\u4f1a\u62a5\u9519\u3002<\/p>\n

    root@ubuntu:~# LIST='\/etc'\r\nroot@ubuntu:~# echo $LIST\r\n\/etc\r\nroot@ubuntu:~# LIST = '\/etc'\r\nLIST: command not found<\/pre>\n
    \u672c\u5730\u53d8\u91cf<\/strong><\/span><\/div>\n

    var_name=value\uff1a\u4f5c\u7528\u57df\u4e3a\u6574\u4e2abash\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528\uff1b
    \n\u53d8\u91cf\u547d\u540d\u89c4\u8303\uff1a<\/p>\n

      \n
    1. \u53ea\u80fd\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\uff0c\u5e76\u4e14\u4ee5\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf\u5f00\u5934\u3002<\/li>\n
    2. \u6700\u597d\u4e0d\u8981\u8ddf\u7cfb\u7edf\u5df2\u6709\u7684\u73af\u5883\u53d8\u91cf\u91cd\u540d\u3002<\/li>\n
    3. \u53d8\u91cf\u540d\u53ef\u5145\u5206\u4f53\u73b0\u8fd9\u4e2a\u53d8\u91cf\u7684\u4f5c\u7528\u3002<\/li>\n<\/ol>\n
      \u5c40\u90e8\u53d8\u91cf<\/strong><\/span><\/div>\n

      \u58f0\u660e\u5c40\u90e8\u53d8\u91cf\u4f7f\u7528\u201clocal\u201d\u547d\u4ee4\uff0c\u5c40\u90e8\u53d8\u91cf\u4f5c\u7528\u57df\u53ea\u5728\u4f5c\u7528\u8303\u56f4\u5185\u6709\u6548\u3002
      \nlocal var_name=value\uff1a\u4f5c\u7528\u57df\u4e3a\u5f53\u524d\u4ee3\u7801\u6bb5<\/p>\n

      \u73af\u5883\u53d8\u91cf<\/strong><\/span><\/div>\n

      \u4f5c\u7528\u57df\u4e3a\u5f53\u524dshell\u8fdb\u7a0b\u53ca\u5176\u5b50\u8fdb\u7a0b\uff0c\u4e0d\u80fd\u5f71\u54cd\u5230\u5176\u7236\u8fdb\u7a0b\uff0c\u58f0\u660e\u73af\u5883\u53d8\u91cf\u4f7f\u7528\u201cexport\u201d\u547d\u4ee4\u3002<\/p>\n

      export var_name=value<\/pre>\n

      \uff0c\u5982\u679c\u53d8\u91cf\u5df2\u7ecf\u5b9a\u4e49\u53ef\u4ee5\u53ea\u662f\u7528\u53d8\u91cf\u540d export var_name\uff0c\u5373\u53ef\u7528\u4e0b\u9762\u4e24\u79cd\u65b9\u5f0f\u58f0\u660e\u73af\u5883\u53d8\u91cf\uff1a
      \n1. export var_name=value
      \n2. var_name=value
      \nexport var_name
      \n\u811a\u672c\u5728\u6267\u884c\u547d\u4ee4\u65f6\u4f1a\u542f\u52a8\u4e00\u4e2a\u5b50shell\u73af\u5883\u53d8\u91cf\uff1a
      \n\u7cfb\u7edf\u81ea\u52a8\u6267\u884c\u7684\u811a\u672c\uff08\u975e\u547d\u4ee4\u884c\u542f\u52a8\uff09\u5c31\u9700\u8981\u81ea\u6211\u5b9a\u4e49\u9700\u8981\u7684\u4e2a\u73af\u5883\u53d8\u91cf<\/p>\n

      \u4f4d\u7f6e\u53d8\u91cf<\/strong><\/span><\/div>\n
      $1\uff0c$2\uff0c$3\uff0c\u2026\u2026\r\ncat first.sh test.txt hello\r\n$1: first.sh\r\n$2: test.txt\r\n$3: hello\r\n<\/pre>\n

      shift\uff1a\u8e22\u6389\u53c2\u6570
      \nshift n\uff1a\u8e22\u6389n\u4e2a\u53c2\u6570\uff0c\u9ed8\u8ba4\u8e22\u6389\u4e00\u4e2a\u53c2\u6570
      \n\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f$0\u4e3a\u8c03\u7528\u8be5\u811a\u672c\u7684\u540d\u5b57\uff0c\u800c\u53c2\u6570\u4f5c\u4e3a\u53d8\u91cf\u7684\u8bdd\u7b2c10\u4e2a\u53d8\u91cf\u4e0d\u80fd\u76f4\u63a5\u5199$10\uff0c\u800c\u9700\u8981\u5199\u6210${10}\u3002<\/p>\n

      \u7279\u6b8a\u53d8\u91cf<\/strong><\/span><\/div>\n

      \n$?\uff1a\u4e0a\u4e00\u4e2a\u547d\u4ee4\u6267\u884c\u72b6\u6001\u7684\u8fd4\u56de\u503c\uff1a
      \n\u7a0b\u5e8f\u6267\u884c\u53ef\u80fd\u6709\u4e24\u79cd\u8fd4\u56de\u503c\uff1a
      \n1. \u7a0b\u5e8f\u6267\u884c\u7ed3\u679c
      \n2. \u7a0b\u5e8f\u72b6\u6001\u8fd4\u56de\u5417\uff080-255\uff09
      \n0 \u5219\u4e3a\u6267\u884c\u6b63\u786e
      \n1-255 \u5219\u6267\u884c\u51fa\u9519\uff081\uff0c2\uff0c127\u7cfb\u7edf\u9884\u7559\uff09\uff1b
      \n\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8fd4\u56de\u503c\u6765\u83b7\u53d6\u4e0d\u540c\u7684\u9519\u8bef\u72b6\u6001\u3002\n<\/p>\n

      \n$#\uff1a\u83b7\u53d6\u5f53\u524dshell\u547d\u4ee4\u884c\u4e2d\u53c2\u6570\u7684\u603b\u4e2a\u6570
      \n$*\uff1a\u83b7\u53d6\u5f53\u524dshell\u7684\u6240\u6709\u53c2\u6570 \u201c$1 $2 $3 \u2026\uff0c\u53d7IFS\u63a7\u5236
      \n$@\uff1a\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u6240\u6709\u53c2\u6570 \u201c$1\u2033 \u201c$2\u2033 \u201c$3\u2033 \u201c\u2026\u201d\uff0c\u4e0d\u53d7IFS\u63a7\u5236
      \n$0 \u83b7\u53d6\u5f53\u524d\u6267\u884c\u7684shell\u811a\u672c\u7684\u6587\u4ef6\u540d
      \n$n \u83b7\u53d6\u5f53\u524d\u6267\u884c\u7684shell\u811a\u672c\u7684\u7b2cn\u4e2a\u53c2\u6570\u503c\uff0cn=1..9
      \n$$ \u83b7\u53d6\u5f53\u524dshell\u7684\u8fdb\u7a0b\u53f7\uff08PID\uff09
      \n$! \u6267\u884c\u4e0a\u4e00\u4e2a\u6307\u4ee4\u7684PID\n<\/p>\n

      \n

      \u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.yunweipai.com\/archives\/4498.html<\/a><\/p>\n

      \u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/linux-bash-var.html<\/a>\u7f16\u8f91\uff1a\u9004\u589e\u5b9d\uff0c\u5ba1\u6838\u5458\uff1a\u6768\u9e4f\u98de<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

      \u5bfc\u8bfb Linux\u4e2d\u7f16\u5199SHELL\u811a\u672c\u5fc5\u7136\u8981\u63a5\u89e6\u5230\u53d8\u91cf\uff0c\u672c\u6587\u5bf9bash\u4e2d\u4e0d\u540c\u7684\u53d8\u91cf\u7c7b\u578b\u8fdb\u884c\u4e00\u4e2a\u7b80\u8981\u8bf4\u660e Bash […]<\/p>\n","protected":false},"author":309,"featured_media":35681,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[80,124],"class_list":["post-35678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-bash","tag-124"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/35678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=35678"}],"version-history":[{"count":15,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/35678\/revisions"}],"predecessor-version":[{"id":264108,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/35678\/revisions\/264108"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/35681"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=35678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=35678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=35678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}