## 50.13. Shell Scripts Must Be Readable and (Usually) Executable

Almost everyone knows that you need to make a program file executable -- otherwise, Unix won't execute it. Well, that's true for directly executable binary files like C and Pascal programs, but it's not quite true for interpreted programs like shell scripts.

The Unix kernel can read an executable binary directly: if there's execute permission, the kernel is happy; it doesn't need read permission. But a shell script has to be read by a user's Unix program (a shell). To read a file, any Unix program has to have read permission. So shell scripts must be readable.

Section 35.17

Shell scripts don't need execute permission if you start the shell and give it the script file to read:

>     % sh scriptfile
>     % sh < scriptfile

The execute permission is a sign for the kernel that it can try to execute the file when you type only the filename:

>     % scriptfile

So shell scripts don't need to be executable -- it's just handy.

-- JP

Copyright © 2003 O'Reilly & Associates. All rights reserved.