อะไร-xหมายถึงที่นี่:
if [ -x /etc/rc.local ] then
ฉันจะหาหน้าคู่มือนี้ได้ifอย่างไร?
help ifไหม
อะไร-xหมายถึงที่นี่:
if [ -x /etc/rc.local ] then
ฉันจะหาหน้าคู่มือนี้ได้ifอย่างไร?
help ifไหม
คำตอบ:
จากman bashหน้า (โดยเฉพาะอย่างยิ่งส่วนการแสดงออกแบบมีเงื่อนไข):
-a file
True if file exists.
-b file
True if file exists and is a block special file.
-c file
True if file exists and is a character special file.
-d file
True if file exists and is a directory.
-e file
True if file exists.
-f file
True if file exists and is a regular file.
-g file
True if file exists and is set-group-id.
-h file
True if file exists and is a symbolic link.
-k file
True if file exists and its ``sticky'' bit is set.
-p file
True if file exists and is a named pipe (FIFO).
-r file
True if file exists and is readable.
-s file
True if file exists and has a size greater than zero.
-t fd True if file descriptor fd is open and refers to a terminal.
-u file
True if file exists and its set-user-id bit is set.
-w file
True if file exists and is writable.
-x file
True if file exists and is executable.
[...]
testใน bash คุณจะไม่เรียกใช้testไบนารี คุณกำลังเรียกใช้งานtestbuiltin ของ bash ซึ่งมีเอกสารที่help testและที่อื่น ๆ man testอาจทำให้เข้าใจผิดในบางกรณีด้วยเหตุผลนั้น
ifตัวเองเป็นคำหลักของเชลล์ดังนั้นคุณสามารถค้นหาข้อมูลเกี่ยวกับมันhelp ifได้ ifตัวเองสาขาเท่านั้นขึ้นอยู่กับว่าคำสั่งต่อไปส่งกลับจริง (0) หรือเท็จ (ไม่เป็นศูนย์) สิ่งที่คุณต้องการจริงๆ แต่เป็นman [หรือman testที่เป็นนามแฝงสำหรับ[ testคำสั่งนั้นกำลังดำเนินการจริงtest -x /etc/rc.localซึ่งทดสอบว่าไฟล์นั้นมีอยู่หรือไม่และสามารถใช้งานได้ (หรือมีสิทธิ์ในการค้นหา)
man [ทำงานเกินไป
ifไม่ใช่ shell builtin เป็นเชลล์คีย์เวิร์ดรันคำสั่งนี้type ifเพื่อตรวจสอบ
จากinfo test:
`-x FILE'
True if FILE exists and execute permission is granted (or search permission, if it is a directory).
จำเป็นต้องใช้สิทธิ์ดำเนินการในไดเรกทอรีเพื่อให้สามารถเข้าไปในซีดีได้ (นั่นคือเพื่อทำให้ไดเรกทอรีบางส่วนเป็นไดเรกทอรีทำงานปัจจุบันของคุณ)
จำเป็นต้องใช้งาน Execute ในไดเรกทอรีเพื่อเข้าถึงข้อมูล "inode" ของไฟล์ภายใน คุณต้องการสิ่งนี้เพื่อค้นหาไดเรกทอรีเพื่ออ่าน inodes ของไฟล์ภายใน ด้วยเหตุนี้สิทธิ์ดำเนินการในไดเรกทอรีจึงมักเรียกว่าสิทธิ์ในการค้นหาแทน