{"id":149,"date":"2010-10-14T09:00:45","date_gmt":"2010-10-14T07:00:45","guid":{"rendered":"http:\/\/blog.sfsoft.it\/?p=149"},"modified":"2010-11-25T22:32:04","modified_gmt":"2010-11-25T20:32:04","slug":"usare-parametri-di-default-in-bash","status":"publish","type":"post","link":"http:\/\/www.sfsoft.it\/blog\/2010\/10\/14\/usare-parametri-di-default-in-bash\/","title":{"rendered":"Usare parametri di default in Bash"},"content":{"rendered":"<p>Pu\u00f2 capitare a volte di dover gestire un parametro non passato di uno script ed usare un valore di default, la sintassi \u00e8 la seguente<\/p>\n<p>[bash]var=${parameter:-defaultValue}[\/bash]<\/p>\n<p>Ad esempio se $1 non \u00e8 passato allo script, &#8220;_jail_dir&#8221; prender\u00e0 come valore di default &#8220;\/home\/phpcgi&#8221;<\/p>\n<p>[bash]_jail_dir=&quot;${1:-\/home\/phpcgi}&quot;[\/bash]<\/p>\n<p>Un esempio di utilizzo<\/p>\n<p>[bash]<br \/>\n.\/script.sh \/jail              # &lt;&#8212; _jail_dir sar\u00e0 \/jail<br \/>\n.\/script.sh \/home\/httpd\/jail   # &lt;&#8212; _jail_dir sar\u00e0 \/home\/httpd\/jail<br \/>\n.\/script.sh                    # &lt;&#8212; _jail_dir sar\u00e0 \/home\/phpcgi (default)<br \/>\n[\/bash]<\/p>\n<p><a href=\"http:\/\/www.cyberciti.biz\/tips\/bash-shell-parameter-substitution-2.html\" target=\"_blank\">http:\/\/www.cyberciti.biz\/tips\/bash-shell-parameter-substitution-2.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pu\u00f2 capitare a volte di dover gestire un parametro non passato di uno script ed usare un valore di default, la sintassi \u00e8 la seguente [bash]var=${parameter:-defaultValue}[\/bash] Ad esempio se $1 non \u00e8 passato allo script, &#8220;_jail_dir&#8221; prender\u00e0 come valore di default &#8220;\/home\/phpcgi&#8221; [bash]_jail_dir=&quot;${1:-\/home\/phpcgi}&quot;[\/bash] Un esempio di utilizzo [bash] .\/script.sh \/jail # &lt;&#8212; _jail_dir sar\u00e0 \/jail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,3],"tags":[52,16,8],"_links":{"self":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/149"}],"collection":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":5,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":301,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/posts\/149\/revisions\/301"}],"wp:attachment":[{"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sfsoft.it\/blog\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}