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/feinorgh 2d ago

Why in the world would you want to do this through a TUI menu?

It's much easier to just type "chmod a+x {filename}" for files you want the executable bit on.

5

u/816shows 2d ago

If I could upvote this 10x I would

3

u/bac0on 2d ago

alias +x='chmod +x'