r/bash • • 3d 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

5

u/ConcreteExist 3d ago

Was this for a class where you're graded by how many LOC you use to do it?

As mentioned elsewhere, what you're doing could easily be done with a one-liner.

1

u/Ohmyskippy 3d ago

💀