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.
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 $
You have two choices. First, you could invoke bash and give it the name of the script as a parameter:
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
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 ...