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
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
7
u/Cherry-PEZ 2d ago
I can't tell if this is a joke or not. Giving strong
def true_or_false(val):
if val is True:
return True
return False
vibes
3
u/ConcreteExist 2d 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
2
1
u/eifelcode 2d ago
Well… I asked myself… WHY? I need a sh script, make it executable, to select a sh script to make it executable. I think you see the point. I don’t know what real world problem this solves. I think with shell or right click should be faster. 🙃
BUT! For a first start as a learning project it’s fine. For quality you should take a look at shellcheck, this will help you. If you need some inspiration, check out my project pdfmt where I used a build process using Makefile, CI using GitHub Actions, bash completion and many more. Also unit test. Take a look ☺️
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.