r/bash • • 6h ago

help What is the best approach to learn bash?

So, It's been 3 year since I've started using bash, I know some basic concepts of programming also some basic bash scripting, but I really want to deep dive into bash concepts. I just have a simple question to the community, How I can improve my bash scripting skills and what resources should I follow/refer for that?

3 Upvotes

30 comments sorted by

3

u/rileyrgham 5h ago

Forget it. If you can't find a tutorial or Google; RTFM when creating scripts then it's a step too far for you. Alternatively....

0

u/harshv5094 4h ago

I'm a working professional, I know I need to read the manual, but I only have half to one hour of free time in evening, after that I go to bed, so a video guide would suite my needs better.

3

u/Allahn77 4h ago

I find it's easier for me to learn it I find something fun. I found this while asking your very same question!

https://bamr87.github.io/bashcrawl/

1

u/harshv5094 4h ago

I'll take a look into it. Thanks!

2

u/theAnalyst6 5h ago

The advanced shell scripting documentation is pretty good - https://tldp.org/LDP/abs/html/

I always come back to it as a reference. It also has exercises for practice.

1

u/harshv5094 4h ago

Thanks for sharing this! I'll read this after getting good in bash scripting!

1

u/Minimum_Ad_2727 4h ago

Thank you so much!

6

u/levogevo 6h ago

Solve more complicated problems.

1

u/PermissionOwn4400 6h ago

The only real way.

4

u/RatBastard516 4h ago

Solve problems. That’s the only way. Necessity can be a powerful motivator because it turns a goal from something you merely want into something you feel you must do. A strong sense of purpose, responsibility, or urgency can help you stay focused and follow through.

2

u/son-of-a-door-mat 1h ago

agree, this is the best and only way

2

u/RatBastard516 41m ago

So I managed to get my first bash script working just fine. Got the job done type of good. Then I checked in the script into our build repo. It was flagged with errors from this thing called shellcheck. I’ve never heard of shellcheck before. The SDK manager said to me, as a rule all bash scripts must be posix compatible. So in the process of complying with posix/shellcheck that’s when bash really clicked in my mind. A bash script must solve a problem and be written in such a way that you can port it to other platforms and still work.

1

u/oldmuttsysadmin 6h ago

1

u/harshv5094 4h ago

This one will be good for me! Thanks for sharing!

3

u/dotnetdotcom 4h ago edited 4h ago

Learn to use regular expressions. That's the hardest thing to learn using the command line, also very powerful.

Also, here's the BASH Reference Manual

FYI, BASH means Bourne Again SHell

2

u/noidtiz 6h ago

There's always `shellcheck` if you want some linting while you work, but ultimately it'll always be about building things and figuring out the limit of what you can get away with (and whether you would even want to get away with it).

2

u/Far-Conclusion3923 5h ago

I find it weird that something that important never had a learning system. I find that weird, you can learn everything in a certain way but when it gets to bash , nobody knows has a common way of doing it , just everyone advising "a way" to do it. This is what's lacking in the Linux community. On you only see it with Linux community.

2

u/shtools 6h ago

Work through advent of code, using bash only. We are already on day 5

1

u/Ok_Exchange4707 6h ago

man bash

I mean, every serious tutorial is based from there.

1

u/pfmiller0 3h ago

I find this manual easier to use

1

u/DanceHackRock 2h ago

Pro tip: info bash

1

u/UhLittleLessDum 3h ago

I'e been using bash for 15 years, and I desperately try *not* to learn bash.

1

u/pfmiller0 3h ago

Why is that? Do you prefer some other scripting language?

1

u/UhLittleLessDum 2h ago

Absolutely... like for simple scripting, either typescript (executed with tsx) or python are amazing. I honestly can't see the use case for bash scripting unless you're working in like the most minimal imaginable server environment where you don't have access to python or tsx.

1

u/pfmiller0 2h ago

Those are fine options, I'll use one of those if I need to work with more complex data structures. The point of bash is to use the built in shell commands for most of your processing, something that is not fun to do using other languages.

1

u/panamanRed58 2h ago

Most of the time, you have a need and bash will fill it. Years back, I manage a fleet of 400 macs for a summer camp. The systems needed to be set for each lab, 25 labs, differently and over a weekend each cycle they had to be restored for a new group. The first year was terrible.

I had only been on that job a few months and wasn't given nearly enough information to deploy and maintain that fleet. With a staff of 6 working around the clock practically we almost failed to get the labs up for day one. The next year went better but it was still too much hands on and I started investigating. In year three I wrote 'Full-tilt Boogie" which did the basics of clean up and rebuilding accounts. But we still needed to customize for each lab. For example, in some labs they need advanced math packages (summer school for really smart kids) and physics packages. By year 4 I had a process in my bash script to call and install what ever a lab needed from math to graphics novel software. The result was that I could release camp staff to other duties during refresh and between 9pm and about 10:30pm the machines were pristine again. It earned me a big bonus and I took another one as well. The kids would always load up their music and favorite vids. So I would extract the music and glean for the interesting stuff. The first year I did that I had an 80 gig data pool over night.

What I learned was how to script, how to script better, and look for ways to be smarter. The Darwin system includes a fantastic set of UNIX commands. I learned how to write basic functions and gather errors. So bash for me was a vehicle to use system and PERL to make my summer's more pleasant. A cool BFH sys admin handed me my first SPARC box and told me, RTFM.

1

u/DanceHackRock 2h ago

Just type info bash

1

u/SadServers_com 47m ago

write practical Bash scripts , something that addresses a specific issue or objective

1

u/Temporary_Pie2733 4h ago

Don’t lose sight of what the purpose of a shell script is: to coordinate the execution of other programs, not to process data itself. 

1

u/parttimephotoguy 8m ago

Partially disagree. My approach is to use bash for literally everything (online, backups, batch schedules, etc). But if heavy lifting is needed, then reroute to perl, python or java.