change all .sh files to executable by terminal

i hate retyping chmod +x filename and insect to run from terminal. how do i set this for all .sh files ? I've tried Inspect then manually setting the extension


Solution 1:

Using a find command would be simple enough:

find . -iname "*.sh" -exec bash -c 'chmod +x "$0"' {} \;

The command breaks down as
find [obvious!]
. = from this folder. You can put a path instead
-iname = case insensitive name
"*.sh" = wildcard filename
-exec = utility to execute commands
bash = what tool you want to use (you can use sh instead)
-c flag means execute the following command as interpreted by this program.
chmod +x = command to change the file to executable
"$0" = The value that was passed to the utility
{} = If the string {} appears anywhere in the utility name or the arguments it is replaced by the pathname of the current file.
; = Terminates the command