{"id":78,"date":"2010-03-24T16:37:55","date_gmt":"2010-03-24T08:37:55","guid":{"rendered":"http:\/\/ali.uitm.edu.my\/?p=78"},"modified":"2010-03-24T16:37:55","modified_gmt":"2010-03-24T08:37:55","slug":"apabila-sudo-echo-blah-rootblah-memberi-error-permission-denied","status":"publish","type":"post","link":"https:\/\/ali.uitm.edu.my\/?p=78","title":{"rendered":"Apabila sudo echo &#8220;blah&#8221; > \/root\/blah memberi error permission denied"},"content":{"rendered":"<p>Kadangkala semasa membuat <em>bash script<\/em>, kita perlu mengisi sesuatu <em>file<\/em> dengan perkataan atau ayat. Oleh kerana <em>file<\/em> itu hanya boleh ditulis oleh <em>superuser<\/em>, kita pun menjalankan arahan berikut:<\/p>\n<blockquote><p>sudo echo &#8220;blah&#8221; &gt; \/root\/blah<\/p><\/blockquote>\n<p>Tetapi kita akan menerima<em> error permission denied<\/em> bila menjalankan arahan diatas. Kenapa ek?<\/p>\n<p>Jawapannya mudah &#8230; sudo hanya boleh digunakan oleh arahan yang pertama sahaja e.g. echo, ianya tidak dibawa oleh redirection untuk menulis kedalam file. Untuk mengatasi masalah diatas kita boleh guna arahan <strong>tee<\/strong> seperti berikut:<\/p>\n<blockquote><p>echo &#8220;blah&#8221; | sudo tee -a \/root\/blah<\/p><\/blockquote>\n<p>-a bermaksud<em> append<\/em> ke dalam file dan bukan <em>overwrite<\/em> data di dalam file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kadangkala semasa membuat bash script, kita perlu mengisi sesuatu file dengan perkataan atau ayat. Oleh kerana file itu hanya boleh ditulis oleh superuser, kita pun menjalankan arahan berikut: sudo echo &#8220;blah&#8221; &gt; \/root\/blah Tetapi kita akan menerima error permission denied bila menjalankan arahan diatas. Kenapa ek? Jawapannya mudah &#8230; sudo hanya boleh digunakan oleh arahan [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=\/wp\/v2\/posts\/78"}],"collection":[{"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":2,"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions\/80"}],"wp:attachment":[{"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ali.uitm.edu.my\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}