UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 22.18 Clear Your Terminal for Security, to Stop Burn-in Chapter 22
File Security, Ownership, and Sharing
Next: 22.20 Why Can't You Change File Ownership Under BSD UNIX?
 

22.19 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.

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 signal to 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


Previous: 22.18 Clear Your Terminal for Security, to Stop Burn-in UNIX Power ToolsNext: 22.20 Why Can't You Change File Ownership Under BSD UNIX?
22.18 Clear Your Terminal for Security, to Stop Burn-in Book Index22.20 Why Can't You Change File Ownership Under BSD UNIX?

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System