SSL: 1
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":52,"date":"2015-08-20T16:08:17","date_gmt":"2015-08-20T08:08:17","guid":{"rendered":"https:\/\/blog.weskiller.com\/?p=52"},"modified":"2015-12-30T12:37:40","modified_gmt":"2015-12-30T04:37:40","slug":"shell%e9%80%bb%e8%be%91%e5%88%a4%e6%96%ad-%e4%b8%89%e7%9b%ae%e8%bf%90%e7%ae%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/blog.gamein.vip\/ternary-operator.html","title":{"rendered":"shell\u903b\u8f91\u5224\u65ad-\u4e09\u76ee\u8fd0\u7b97\u7b26"},"content":{"rendered":"
\u5728C\u8bed\u8a00\u4e2d\u4e09\u76ee\u8fd0\u7b97\u7b26\u7684\u7ec4\u6210\u662f<\/p>\n
\r\n<\u8868\u8fbe\u5f0f1>?<\u8868\u8fbe\u5f0f2>:<\u8868\u8fbe\u5f0f3>;\r\n<\/pre>\n\u7b49\u540c\u4e8eC\u8bed\u8a00\u4e2d\u7684if\u8bed\u53e5<\/p>\n
\r\nif (\u8868\u8fbe\u5f0f1)\r\n \u8868\u8fbe\u5f0f2;\r\nelse\r\n \u8868\u8fbe\u5f0f3;\r\n<\/pre>\n\u800c\u5728bash shell \u4e2d\u4e5f\u6709\u7c7b\u4f3c\u7684\u65b9\u5f0f<\/p>\n
\r\necho $((2>1?2:1))\r\n<\/pre>\n\u4f46\u662f\u9019\u91cc $(()) \u53ea\u80fd\u8fdb\u884c\u6570\u503c\u5927\u5c0f\u7684\u5224\u65ad
\n\u4f7f\u7528command\u8fdb\u884c\u4e09\u76ee\u8fd0\u7b97\u5e94\u8be5\u8fd9\u6837\u4f7f\u7528<\/p>\n\r\ncommand1 && command2 || command3\r\n<\/pre>\n\u5728shell\u4e2d\uff0c\u5f88\u591a\u4eba\u7406\u89e3\u4e3a\u4e0b\u9762\u7684if\u8bed\u53e5<\/p>\n
\r\nif command1;then\r\n command2\r\nelse\r\n command3\r\nfi\r\n<\/pre>\n\u8fd9\u662f\u9519\u8bef\u7684\uff0c\u539f\u56e0\u662f\u6ca1\u6709\u6df1\u523b\u7406\u89e3&& \u548c ||
\n\u4e0b\u9762\u7684\u547d\u4ee4\u5f88\u597d\u7684\u6307\u51fa\u9519\u8bef\u7684\u539f\u56e0<\/p>\n\r\n#date && echo "It's sunny today" || echo "the weather is terrible"\r\nThu Aug 20 11:09:35 EDT 2015\r\nIt's sunny today\r\n#date && "It's sunny today" || echo "the weather is terrible"\r\nThu Aug 20 11:10:45 EDT 2015\r\n-bash: It's sunny today: command not found\r\nthe weather is terrible\r\n<\/pre>\n||\u4f1a\u5224\u65ad\u524d\u4e00\u6761\u547d\u4ee4\u7684\u72b6\u6001\u8fd8\u56de\u503c\uff0c\u5982\u679c\u4e3afalse\uff0c\u5c31\u6267\u884c\u540e\u9762\u7684\u8bed\u53e5
\n\u5728\u8fd9\u91cc “It’s sunny today” \u547d\u4ee4\u662f\u9519\u8bef\u7684\uff0c\u4e8e\u662f\u540e\u9762 echo “the weather is terrible” \u5c31\u6267\u884c\u4e86
\n\u6df1\u5165\u7814\u7a76
\n\u4f7f\u7528{}\u89e3\u51b3||\u5224\u65ad\u95ee\u9898<\/p>\n\r\ncommand1 && { command2 ;echo -n ;} || commadn3\r\n<\/pre>\n\u5982\u679ccommand1\u6b63\u786e ||\u5c31\u53ea\u4f1a\u63a5\u53d7\u6765\u81eaecho -n\u7684\u72b6\u6001\u8fd8\u56de\u503c,\u6240\u4ee5\u4e0d\u4f1a\u6267\u884c\u540e\u9762\u7684command3
\n\u5982\u679ccommand1\u5931\u8d25 &&\u76f4\u63a5\u8df3\u8fc7\uff0c||\u5224\u65adcommand1\u5931\u8d25\uff0c\u6267\u884ccommand3
\n\u4e09\u76ee\u8fd0\u7b97\u7b26\u7684\u4e3b\u8981\u76ee\u7684\u662f\u8fbe\u5230\u7b80\u5199\u7684\u529f\u80fd\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u7b80\u5355if\u8bed\u53e5
\n\u5728\u65e5\u5e38\u4f7f\u7528\u4e2d 1 && 2 || 3 \u786e\u5b9e\u5f88\u5b9e\u7528
\n\u4e0b\u9762\u4e3e\u51e0\u4e2a\u5217\u5b50<\/code><\/p>\n\u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728,\u5982\u679c\u5b58\u5728\u5c31\u7ee7\u7eed\u6267\u884c\u811a\u672c\uff0c\u4e0d\u5b58\u5728\u5c31\u9000\u51fa\u62a5\u9519<\/span><\/p>\n
\u4f7f\u7528if\u5224\u65ad\u6587\u4ef6\u5b58\u5728\uff0c\u7136\u540eelse\u90e8\u5206\u5199exit\u3002~~but\uff0c<\/p>\n
\r\nif [ -e $path ];then\r\n ??\r\nelse\r\n exit 1\r\nfi\r\n<\/pre>\n\u5982\u679c\u6587\u4ef6\u5b58\u5728\u5982\u4f55\u8fdb\u884c?
\n\u8fd9\u4e2a\u65f6\u5019\u53ea\u80fd\u53cd\u5411\u601d\u8def\uff0c\u4e0d\u5b58\u5728\u600e\u4e48\u6837\uff0c\u4f46\u662f\u8fd9\u6837\u5c31\u548c\u5224\u65ad\u903b\u8f91\u76f8\u53cd<\/p>\n\r\nif [ ! -e $path ];then\r\n exit 1\r\nfi\r\n<\/pre>\n\u4f46\u662f\u8fd9\u6837\u5c31\u7b80\u4fbf\u4e86\u5f88\u591a<\/p>\n
\r\n[ -e $path ] || exit 1\r\n<\/pre>\n\u9700\u8981\u6709\u987a\u5e8f\u7684\u8fde\u7eed\u6267\u884c\u591a\u6761\u547d\u4ee4\uff0c\u5e76\u4e14\u5224\u65ad\u547d\u4ee4\u6b63\u786e,\u5982\u679c\u547d\u4ee4\u9519\u8bef\u5c31\u6267\u884c “echo error”<\/span><\/p>\n
\u5728\u8fd9\u91cc\u5982\u679c\u4f7f\u7528if\u5c31\u9700\u8981\u5d4c\u5957\u591a\u5c42\uff0c\u5341\u5206\u9ebb\u70e6\uff0c\u4e5f\u6d6a\u8d39\u65f6\u95f4<\/p>\n
\r\nif command1;then\r\n if command2;then\r\n if command3;then\r\n command4\r\n else\r\n echo "error"\r\n fi\r\n else\r\n echo "error"\r\n fi\r\nelse\r\n echo "error"\r\nfi\r\n<\/pre>\n\u800c\u4f7f\u7528&&\u5c31\u7b80\u5316\u4e86\u5f88\u591a<\/p>\n
\r\ncommad1 && command2 && command3 && command4 || echo "error"\r\n<\/pre>\n\u535a\u4e3b\u5f88\u559c\u6b22\u4f7f\u7528\u4e09\u76ee\u8fd0\u7b97\u7b26\u8fdb\u884c\u903b\u8f91\u7684\u5224\u65ad
\n\u4e0b\u9762\u662f\u4e3e\u4f8b<\/p>\n\r\n#\u5728\u5f88\u591a\u811a\u672c\u4e2d\u9700\u8981\u7248\u5224\u7cfb\u7edf\u662f\u5426\u5b58\u5728\u5b89\u88c5\u5305\u6216\u8005\u547d\u4ee4\r\n[ -e \/usr\/sbin\/iptables ] || { echo "iptables-services not installed" && exit 1 ;}\r\n#\u535a\u4e3b\u7f16\u5199\u6bd4\u8f83\u4e24\u4e2a\u6587\u4ef6\u5939\u5dee\u5f02\u7684\u811a\u672c\u4e2d\uff0c\u5982\u679c\u53c2\u6570\u662f\u4e24\u4e2a\u5b58\u5728\u7684\u6587\u4ef6\u8fdb\u884c\u7684\u5224\u65ad\r\n[ -f "$1" ] && [ -f "$2" ] && { cmp $1 $2 >\/dev\/null 2>&1 && echo 'The two files are the same' && exit 0|| { echo -ne $red 'The two files are not same'\\n && exit 0 ;} ;}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u5728C\u8bed\u8a00\u4e2d\u4e09\u76ee\u8fd0\u7b97\u7b26\u7684\u7ec4\u6210\u662f <\u8868\u8fbe\u5f0f1>?<\u8868\u8fbe\u5f0f2>:<\u8868\u8fbe\u5f0f3>; […]<\/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":[7],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-linux","category-shell","tag-7"],"_links":{"self":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/52","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=52"}],"version-history":[{"count":26,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/52\/revisions\/111"}],"wp:attachment":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}