Chapter 19. Tips and Traps: Common Goofs for Novices
Nobody’s perfect. We all make mistakes, especially when we are first learning something new. We have all been there, done that. You know, the silly mistake that seems so obvious once you’ve had it explained, or the time you thought for sure that the system must be broken because you were doing it exactly right, only to find that you were off by one little character—one which made all the difference. Certain mistakes seem common, almost predictable, among beginners. We’ve all had to learn the hard way that scripts don’t run unless you set execute permissions on them—a real newbie kind of error. Now that we’re experienced, we never make those mistakes anymore. What, never? Well, hardly ever. After all, nobody’s perfect.
19.1 Forgetting to Set Execute Permissions
Problem
You’ve got your script all written and want to try it out, but when you go to run the script you get an error message:
$ ./my.script bash: ./my.script: Permission denied $
Solution
You have two choices. First, you could invoke bash and give it the name of the script as a parameter:
bash my.script
Or second (and better still), you could set execute permissions on the script so that you can run it directly:
chmod a+x my.script ./my.script
Discussion
Either method will get the script running. You’ll probably want to set execute permissions on the script if you intend to use it over and over. You only have to do this once, thereafter allowing you to invoke it ...
Get bash Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.