{"id":1182,"date":"2014-10-22T15:05:11","date_gmt":"2014-10-22T07:05:11","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=1182"},"modified":"2023-10-31T15:44:49","modified_gmt":"2023-10-31T07:44:49","slug":"shecll-script-dialog","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=1182","title":{"rendered":"Shell Script Dialog"},"content":{"rendered":"<ol>\n<li>\n<p>Dialog \u9810\u8a2d\u8a2d\u5b9a\u901a\u5e38\u5728\u500b\u4ebaHome\u76ee\u9304\u4e0b\u7684\u6a94\u6848&#8221;.dialogrc&#8221;<br \/>\n\u53ef\u4f7f\u7528\u6307\u4ee4 &#8220;dialog &#8211;create-rc ~\/.dialogrc&#8221; \u7522\u751f<\/p>\n<\/li>\n<li>\n<p>\u56e0\u70ba\u9810\u8a2d\u5e95\u8272\u662f\u9752\u8272\uff0c\u7d50\u675f\u5f8c\u6703\u6709\u8272\u584a\u6b98\u7559\uff0c\u6240\u4ee5\u5efa\u8b70\u5c07screen_color\u8abf\u6574\u70ba\u9ed1\u8272<br \/>\n\u4e5f\u53ef\u5728 dialog \u6307\u4ee4\u57f7\u884c\u524d\u5148\u6307\u5b9a\u4f7f\u7528\u54ea\u4e00\u500b\u8a2d\u5b9a\u6a94\u6848\u9032\u884cdialog<br \/>\n&#8220;export DIALOGRC=${path}\/dialog.installer&#8221;<br \/>\n\u8a18\u5f97\u96e2\u958b\u524d\u628aDIALOGRC\u6e05\u7a7a\u5c31\u597d<\/p>\n<\/li>\n<li>\n<p>\u4e0b\u9762\u662f\u5c07\u5e38\u7528\u7684dialogrc\u5beb\u6210function<\/p>\n<\/li>\n<\/ol>\n<pre lang=\"bash\">\ndialog_msgbox() {\n  #$1 => msgbox\u7684\u985e\u5225{no clear, clear, clear & exit}, $2 => \u524d\u8996\u7a97\u7684\u6587\u5b57\u8aaa\u660e, $3 => \u986f\u793a\u7684\u8cc7\u8a0a\u6587\u5b57\n  case $1 in\n    0) \n      dialog --backtitle \"${backtitle}\" --title \"$2\" --msgbox \"n${3}\" 9 50;;\n    1)\n      dialog --backtitle \"${backtitle}\" --title \"$2\" --clear --msgbox \"n${3}\" 9 50;;\n    2)\n      dialog --backtitle \"${backtitle}\" --title \"$2\" --clear --msgbox \"n${3}\" 9 50\n      export DIALOGRC=\n      exit 1;;\n  esac\n}\n\ndialog_infobox() {\n  #$1 => \u524d\u8996\u7a97\u7684\u6587\u5b57\u8aaa\u660e, $2 => \u986f\u793a\u7684\u8cc7\u8a0a\u6587\u5b57\n  dialog --backtitle \"${backtitle}\" --title \"${1}\" --infobox \"${2}\" 5 50\n  sleep 1\n}\n\ndialog_inputbox() {\n  #$1 => \u524d\u8996\u7a97\u7684\u6587\u5b57\u8aaa\u660e, $2 => \u986f\u793a\u7684\u8cc7\u8a0a\u6587\u5b57, $3 => \u9810\u8a2d\u503c\n  exec 3>&1\n  inputtext=$(dialog --backtitle \"${backtitle}\" --title \"${1}\" --inputbox \"${2}\" 10 60 ${3} 2>&1 1>&3)\n  exec 3>&-\n}\n\ndialog_yesno() {\n  #$1 => \u524d\u8996\u7a97\u7684\u6587\u5b57\u8aaa\u660e, $2 => \u986f\u793a\u7684\u8cc7\u8a0a\u6587\u5b57\n  dialog --backtitle \"${backtitle}\" --title \"${1}\" --yesno \"${2}\" 7 60\n  return $?\n}\n\ndialog_passwdbox() {\n  #$1 => \u524d\u8996\u7a97\u7684\u6587\u5b57\u8aaa\u660e, $2 => \u986f\u793a\u7684\u8cc7\u8a0a\u6587\u5b57\n  exec 3>&1\n  inputtext=$(dialog --backtitle \"${backtitle}\" --title \"${1}\" --insecure --clear --passwordbox \"${2}\" 10 60 2>&1 1>&3)\n  exec 3>&-\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dialog \u9810\u8a2d\u8a2d\u5b9a\u901a\u5e38\u5728\u500b\u4ebaHome\u76ee\u9304\u4e0b\u7684\u6a94\u6848&#8221;.dialogrc&#8221; \u53ef\u4f7f\u7528\u6307\u4ee4 &#8220;dialog &#8211;create-rc ~\/.dialogrc&#8221; \u7522\u751f \u56e0\u70ba\u9810\u8a2d\u5e95\u8272\u662f\u9752\u8272\uff0c\u7d50\u675f\u5f8c\u6703\u6709\u8272\u584a\u6b98\u7559\uff0c\u6240\u4ee5\u5efa\u8b70\u5c07screen_color\u8abf\u6574\u70ba\u9ed1\u8272 \u4e5f\u53ef\u5728 dialog \u6307\u4ee4\u57f7\u884c\u524d\u5148\u6307\u5b9a\u4f7f\u7528\u54ea\u4e00\u500b\u8a2d\u5b9a\u6a94\u6848\u9032\u884cdialog &#8220;export DIALOGRC=${path}\/dialog.installer&#8221; \u8a18\u5f97\u96e2\u958b\u524d\u628aDIALOGRC\u6e05\u7a7a\u5c31\u597d \u4e0b\u9762\u662f\u5c07\u5e38\u7528\u7684dialogrc\u5beb\u6210function dialog_msgbox() { #$1 => msgbox\u7684\u985e\u5225{no clear, clear, clear &#038; exit}, $2 => \u524d\u8996\u7a97\u7684\u6587\u5b57\u8aaa\u660e, $3 => \u986f\u793a\u7684\u8cc7\u8a0a\u6587\u5b57 case $1 in 0) dialog &#8211;backtitle &#8220;${backtitle}&#8221; &#8211;title &#8220;$2&#8221; &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=1182\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-1182","post","type-post","status-publish","format-standard","hentry","category-shell-script"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1182"}],"version-history":[{"count":1,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1182\/revisions"}],"predecessor-version":[{"id":1989,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1182\/revisions\/1989"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}