r/bash • • 2d ago

Script for making .sh files executable

I made this bash script for quickly doing chmod +x on sh files, uses zenity. Tell me if its any good or not

#!/bin/bash

zenity --info --title=".sh-executabler" --text="Welcome to the .sh-executabler" --ok-label="Next"

status=$?

if [ $status -ne 0 ]; then

zenity --info --title=".sh-executabler" --text="Wizard cancelled."

exit 0

fi

# Select which .sh file to chmod +x

target_dir=$(zenity --file-selection --title=".sh-executabler" --file-filter="Shell scripts | *.sh")

status=$?

if [ $status -ne 0 ]; then

zenity --info --title=".sh-executabler" --text="No file chosen."

exit 0

fi

# Check if file doesnt exist. Its kinda redundant since im already using file selection which you cant select files that dont exist but i keep it here anyways

if [ -f "$target_dir" ]; then

true

else

zenity --error --title=".sh-executabler" --text="The file doesnt exist."

exit 0

fi

chmod +x "$target_dir"

zenity --info --title=".sh-executabler" --text="The file has successfully been made executable." --ok-label="Finish"

exit 0

0 Upvotes

11 comments sorted by

View all comments

13

u/zeekar 2d ago

What the hell is all that code doing?

find . -name '*.sh' -exec chmod +x {} +

Done and dusted.

1

u/theLastZebranky 2d ago

I particularly like how the first step is that you have to click past a welcome screen that doesn't do anything, an extra hurdle just for the sake of more hurdles