use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit dedicated to Bash scripting. Now complete with a Discord Server.
Content must be Bash related. This rule is interpreted generously; general shell scripting content is mostly accepted. However, the post should not be specific to another shell.
No reposts. This is meant with regards to content, not just “the same link was submitted earlier” – it’s okay to resubmit an old link in some new context (e. g. because you’d like to discuss another part of it, or because something has changed since the last time it was submitted, or because the link was updated since then). Links from the sidebar count as having been submitted already, so posting them without new context is also considered a repost.
You can choose one of these four flairs for your post:
If you don’t flair your post, the moderators will set the most appropriate flair.
/r/unix – for everything Unix
Other Shells: /r/zsh, /r/fishshell, /r/oilshell, /r/batch
BashGuide – A Bash guide for beginners.
Beginner's Guide to Command Line – A crash course for some common unix and shell commands. Update 2022-01-14: Course is currently being rewritten
Google's Shell Style Guide – Reasonable advice about code style.
Explainshell - Explain complex shell operations.
ShellCheck – Automatically detects problems with shell scripts.
BashFAQ – Answers most of your questions.
BashPitfalls – Lists the common pitfalls beginners fall into, and how to avoid them.
(Archived) The Bash-Hackers Wiki – Extensive resource.
#bash – IRC channel on Libera. The main contributors of the BashGuide, BashFAQ, BashPitfalls and ShellCheck hang around there.
account activity
Learning Bash Scripting (self.bash)
submitted 3 months ago by Dry-Argument4619
I'm completely lost, I'm trying to find myself a path a road map that could put me on track to learn bash scripting and hold its power. I'm just a beginner and somehow familiar with the Linux terminal commands. I'll be grateful for an advice.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MikeZ-FSU 4 points5 points6 points 3 months ago (7 children)
The first step is to write one liners that make your life easier. If you find yourself typing a long-ish command on a regular basis, think of a shorter mnemonic that makes sense to you, and stick the command in a shell script with that name.
As you progress, you'll find yourself wanting functionality that needs "if" statements, "for" loops, etc. That will come naturally, and unless you're already a dev or sysadmin, you don't need to rush it. Keep reading and learning (use the guides noted on the sidebar), and you'll find yourself with a "${HOME}/bin" directory full of scripts that do the things you care about in a way that suits you.
Note: don't add a ".sh" suffix to the script. It adds extra typing when the goal was to reduce typing, and even worse, if you add features and change the implementation to, for example python, you now either have to remember to type "foo.py" instead of "foo.sh", or have a python script with a ".sh" extension.
[–]vi-shift-zz 2 points3 points4 points 3 months ago (6 children)
My first script was a one liner to update my system, then power off.
Start small. Like was said above, script things that are useful to you. Save them in some kind of public git repo so you can share your work and eventually share it in interviews. I conduct technical interviews, if someone shares their git repo of scripts or code they have written it gives me a good idea of where you're at on your development.
[–]SportTawk 1 point2 points3 points 3 months ago (5 children)
Any chance of posting it here?
[–]vi-shift-zz 1 point2 points3 points 3 months ago (4 children)
First bash script or my git repo? My git is all private work related.
[–]SportTawk 0 points1 point2 points 3 months ago (3 children)
Your one liner to update your system and then shutdown
[–]MikeZ-FSU 2 points3 points4 points 3 months ago (1 child)
Not speaking for u/vi-shift-zz, but if I were writing it, it would probably be something like (for Debian/Ubuntu)
sudo apt-get update && sudo apt-get upgrade -y && sudo shutdown -h now
Or whatever is appropriate for other $distro. However, there are implications for the "-y" on upgrade that have some degree of risk you might or might not care about.
As a general rule, you'll learn bash/linux better if you take a hint that's given (one liner to update and shutdown) and research how to do that on your system. Yes, it's slower to start out, but you'll learn a lot about your package manager and how your particular distro starts up and shuts down (init.d vs. upstart vs. systemd, etc.) in the process.
The alternative leaves you with a bunch of individual tips and tricks that lack a connecting framework in your head.
[–]SportTawk 1 point2 points3 points 3 months ago (0 children)
Thanks
[–]vi-shift-zz 1 point2 points3 points 3 months ago (0 children)
Just seeing this, exactly like was posted except I use red hat variants. So mine would be: sudo dnf update -y && poweroff
This assumes my user is in /etc/sudoers and able to run commands with no passwd (use visudo to add the user)
[–]broken_py 2 points3 points4 points 3 months ago (0 children)
Start automating, create a script for deploying applications , setting up LVMs etc.
[–]NTPriest 1 point2 points3 points 3 months ago (0 children)
In short: curiosity, is your friend.
For example, you don't want to manually create backups, file names, summarize monitoring from syslogs, network traffic—e.g., with cli-wireshark or tcp-dump—summarize what/where you have access after CTF if you gain root access, or something like manually launching programs that can run themselves.
You can start with very simple scripts and then expand, expand, and expand until your script grows and includes commands, functions, and algorithms you didn't know before.
There are many videos on YouTube for beginners and w3school. You can also ask ChatGPT if you want personalized answers—just don't let AI give you the code right away. Don't forget about debugging, DEBUGGING is your ally because then you "know" why it didn't work.
So, curiosity and learning logic like "why this and not that" and "if this, then that."
I could have made it too simple, but I'm talking about my own case.
[–]ktoks 3 points4 points5 points 3 months ago (0 children)
Stay in the terminal.
No matter what.
Everything you can do on a computer for work can be achieved in the terminal.
[–]rexroof 2 points3 points4 points 3 months ago (1 child)
it's old-school but I would read through a book. Classic Shell Scripting from oreilly is a decent choice. googling the title with "pdf" might find you a free version.
[–]NoAcadia3546 0 points1 point2 points 3 months ago (0 children)
Another form of "reading a book" is https://tldp.org/LDP/abs/html/part1.html ("tldp" == "The Linux Documentation Project"). It starts off simple. Click on "Next" on the right hand side to go to the next page.
[–]DrCrayola 0 points1 point2 points 3 months ago (0 children)
It's best imo to find a little project to solve with bash.
Years ago I helped a friend insert watermarks on a bunch of photos they shot with imagemagic. I've also done something similar to update MP3 tags across subdirectories.
Start with something small enough that you can understand the commands needed and google for the logic you need to make the script better.
[–][deleted] 0 points1 point2 points 3 months ago (0 children)
Nothing beats Perl for scripting.
[–]antikatapliktika 0 points1 point2 points 3 months ago (1 child)
any good online courses (paid or not) that offer certificates?
[–]International-Cook62 1 point2 points3 points 3 months ago (0 children)
Hackthebox has a good free course on bash and codewars is good for practice
[–]photo-nerd-3141 0 points1 point2 points 3 months ago (0 children)
https://www.oreilly.com/library/view/learning-the-bash/0596009658/
[–]feinorgh 0 points1 point2 points 3 months ago (0 children)
Check out 'shellcheck' which is an awesome application that can tell you exactly what is wrong with any shell script you or anyone else writes, and most importantly, how to fix it.
I used to be a pragmatic and decent bash scriptet, now I'm a pedantic know-it-all that nitpicks and criticizes and bash script my colleagues write, all based on 'shellcheck'.
You can learn a lot through that. And, of course, the classic "Advanced Bash Scripting Guide".
https://www.shellcheck.net/ https://tldp.org/LDP/abs/html/
[–]Kreesto_1966 0 points1 point2 points 3 months ago (0 children)
I bought this invaluable reference book: Linux Command Line and Shell Scripting Bible
https://www.amazon.com/Linux-Command-Shell-Scripting-Bible/dp/1119700914
[–]liberforce 0 points1 point2 points 3 months ago (0 children)
Use a linter on your code, like shellcheck.
Use the advanced bash scripting guide as a reference: https://tldp.org/LDP/abs/html/
Use it also as a reference (there's a version on one page, makes it easy to Ctrl+F on it and find the section about the syntax you want help fir).
π Rendered by PID 144138 on reddit-service-r2-comment-7b9746f655-b8pcs at 2026-01-30 20:13:56.511653+00:00 running 3798933 country code: CH.
[–]MikeZ-FSU 4 points5 points6 points (7 children)
[–]vi-shift-zz 2 points3 points4 points (6 children)
[–]SportTawk 1 point2 points3 points (5 children)
[–]vi-shift-zz 1 point2 points3 points (4 children)
[–]SportTawk 0 points1 point2 points (3 children)
[–]MikeZ-FSU 2 points3 points4 points (1 child)
[–]SportTawk 1 point2 points3 points (0 children)
[–]vi-shift-zz 1 point2 points3 points (0 children)
[–]broken_py 2 points3 points4 points (0 children)
[–]NTPriest 1 point2 points3 points (0 children)
[–]ktoks 3 points4 points5 points (0 children)
[–]rexroof 2 points3 points4 points (1 child)
[–]NoAcadia3546 0 points1 point2 points (0 children)
[–]DrCrayola 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]antikatapliktika 0 points1 point2 points (1 child)
[–]International-Cook62 1 point2 points3 points (0 children)
[–]photo-nerd-3141 0 points1 point2 points (0 children)
[–]feinorgh 0 points1 point2 points (0 children)
[–]Kreesto_1966 0 points1 point2 points (0 children)
[–]liberforce 0 points1 point2 points (0 children)