How to fix “unary operator expected error” in bash script

Posted In Shell - By Tum. On Friday, April 12th, 2013 With 0 Comments

bash
หากเขียน shell script แล้วเมื่อเวลารันทดสอบเกิด error ตามตัวอย่างด้านล่าง

[: =: unary operator expected error

ให้ลองตรวจสอบเงื่อนไข if ในบรรทัดที่ฟ้อง error ดูว่าตัวแปรมีค่าหรือไม่ และมีการเขียน code แบบ [ $Ans = “Y” ] หรือไม่

ถ้าใช่ให้ลองให้ไขเป็น

* ถ้าหากใช้ [[ เราไม่ต้องกังวลเรื่องตัวแปรว่ามีค่าหรือไม่

หรือ

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*