How Can I Improve My Bash Script for Installing Software?

0
5
Asked By CreativeCoder42 On

I'm working on a project where I'm trying to create a script to help me install some software on my laptop. It's meant to be a generic script, but I feel like there are definitely areas where I could improve it. I'd appreciate any suggestions you might have, and if you're up for it, feel free to submit a pull request! Here's the link to my repository: [https://github.com/aniketrath/scripts](https://github.com/aniketrath/scripts)

4 Answers

Answered By ScriptSavvy99 On

I took a quick look at your script, and here are a few pointers:
1. Make sure to check if the script is run as root to avoid permission issues.
2. When detecting the package manager, you might want to streamline how you check with `command -v`. It's good practice to handle errors with `printf` to stderr rather than using `echo`.
3. You may want to structure your conditional branches more clearly using `case` for cleaner code. Keep improving your coding style!

CreativeCoder42 -

Awesome feedback! I'll definitely work on those points.

Answered By ShellToolFan On

Consider installing and running this tool called ShellCheck. It provides really helpful advice on improving shell scripts. It's available on most Linux distros and could save you some time with best practices!

CreativeCoder42 -

I'll check out ShellCheck, thanks for the recommendation!

Answered By FocusedCoder On

If this script is just for your personal use, you might want to customize it specifically for your own setup, rather than making it generic for different users. Here’s a link to my own setup script that might give you some ideas: [https://github.com/adityaathalye/bash-toolkit/blob/master/machine-setup.sh](https://github.com/adityaathalye/bash-toolkit/blob/master/machine-setup.sh)

CreativeCoder42 -

Thanks for sharing your script! I'll take a look at it.

Answered By HelpfulHacker77 On

You might want to check out the 'select' case method for creating menus in your script. It's a more organized way to handle adding new items since it automatically takes care of the numbering for you. Also, just a heads up—your NixOS configuration has your admin password in it, which could be a security concern!

CreativeCoder42 -

Thanks for the tip! I'll definitely look into the 'select' method, and I'll make sure to handle the NixOS config properly.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.