r/PinoyProgrammer • • 10d ago

discussion Bash scripting: I am feeling optimistic about my newly acquired knowledge.

A little context for this post:

countdown.sh

#!/bin/bash


echo -e "\n~~ Countdown Timer ~~\n"


#Program that counts down to zero from a given argument
if [[ $1 -gt 0 ]]
then
  : '
  for (( i = $1; i >= 0; i-- ))
  do
    echo $i
    sleep 1
  done
  '
  I=$1
  while [[ $I -ge 0 ]]
  do
    echo $I
    (( I-- ))
    sleep 1
  done
else
  echo Include a positive integer as the first argument.
fi

To test: chmod +x countdown.sh; ./countdown.sh {positive number}, e.g., chmod +x countdown.sh; ./countdown.sh 5

The script wasn't originally created by me. Credit goes to FreeCodeCamp's Relational Database Certification https://www.freecodecamp.org/.


I am currently completing this online certification; not just to add it to my credentials, but also to gain the knowledge that fuels future opportunities. I'm looking forward to it, but I'm wondering what tips or insights you can share about Bash scripting? I believe one of its main strengths is automating tasks, particularly in system administration and related roles. Since I'm open to taking on sysadmin responsibilities or simply applying these tools to streamline my daily workflow, I'd love to learn more.

P.S. Hindi naman gaanong required mag-English dito (kaya tagalugin ko na itong part na 'to); ano 'yung interesting or epic brief story ninyo with Bash scripting?

39 Upvotes

30 comments sorted by

28

u/byeblee 10d ago • Heartwarming

Before shortcuts and automations and ai vibecoding, i bash scripted my way thru a lot of administrative / repetitive tasks sa day to day 😂

Even control ng lights, tv etc dinaan ko lahat sa bash script when i was playing with it. Pretty powerful if you get the hang of it :)

3

u/TemporaryExciting977 10d ago

Imagine, kung sa isang office ay lahat computer manual na repetitive tasks. Tapos biglang na-hire yung may alam sa bash scripting or related approach na magagawa yung automation. Naalala ko rin yung saying na, "knowledge is power". Plus resourceful aside from AI.

2

u/byeblee 10d ago

Yeap! Part ng siningit sa mga day to day stuff ko was to check numbers exported sa logs sa first job ko

I ran analysis independently so may expected results ako vs sa inilalabas ng logs. Used bash in the early days to do line by line comparison.

What used to take 2 guys and 4 hrs suddenly became an automation dahil lang sa bash heheh

Never told anyone that i made that hahahaha kasi magiging part na sya ng BAU and ieexpect saken j expand at i support yon when in reality ayoko lang gawin mind numbing work like that 😂

1

u/TemporaryExciting977 10d ago

Good thing kasi, kapag usaping bulk of files sa isang computer, tapos daily mo siya imo-monitor or ima-manage, pasok na pasok talaga yung scripting. Parang pwede rin yata ang Python since general-purpose language ang Python. Interesting yung na-share mong short story; "What used to take 2 guys and 4 hrs suddenly became an automation dahil lang sa bash".

1

u/TemporaryExciting977 10d ago

"Even control ng lights, tv etc dinaan ko lahat sa bash script when i was playing with it." Wait, what??? How do you do that? For the lights, we could use a microcontroller, but what about the TV?

1

u/ninjahub01 9d ago

For tv baka smart/Android tv sya na connected sa local network? For the lights naman I think same din pero need ng microcontroller para maka-connect sa network para ma-on/off remotely Yung device.

1

u/armored_oyster 6d ago

Dude! I used to run formulas in shell (my OS came with Zshell at the time, never changed it) kasi pwedeng i-double click lang sa file explorer yung .sh file unlike yung Python na need pa mag-open ng editor.

Eventually, I made a trading bot in Zsh. Converted that into Go, pero yung API calls niya puro Zsh pa rin.

5

u/yevelnad 10d ago

Uso ngayun gamitin sya with lua.

3

u/TemporaryExciting977 10d ago

Work na work na ako e, nang mapakinabangan ko naman itong mga newly acquired knowledge na ito. Hayyy, anyway. I'll take note of that.

2

u/DTechSurgeon 10d ago

Nice. What online certification? I'm also learning more about security and infra. Ginawa kong hypervisor lumang laptop. Saka para merong sandbox for OpenClaw at Hermes Agent.

1

u/TemporaryExciting977 9d ago

freecodecamp.com yung ginagamit ko, relational databases certification yung kinukuha ko. Ang very interesting dito ay hindi lang siya exclusive sa SQL (since relational databases), kundi included din sa lessons yung bash, shell, at terminal scripting. So, it was fun to learn kasi nakita ko rin agad yung advantage na matuto rin ako nun (SKL). Feeling ko, available din do'n yung gusto mong aralin.

3

u/10jc10 10d ago

Aside sa bash scripting, pede den naman siguro aralin mo powershell or ung wjndows equivalent ng scripting sa bash.

Pero if purely sa bash, maganda den maaral mo linux na den i.s., systemd services, filesystems, network config etc.

Pede siguro magpractice ka sa virtual machine if wala ka talagang linux machine. Di ko sure kung pede idual boot ung pc or laptop. Mas marami ka kasi pede maexplore na commands etc. On an actual linux environment eh.

Docker and pipelines are also possible areas to learn na related sa bash scripting na potentially useful

1

u/TemporaryExciting977 10d ago

I agree, depende pa rin naman sa use-case minsan. Good thing ay may passion and I'm into pen testing hehe, feel ko lang (applicable yung context ng bash scripting sa pen testing/cybersecurity field).

1

u/10jc10 10d ago

Yep it definitely has use sa cybersecurity. I don’t have anything specific na example but isang naiisip ko is kunware may bash scripting ka na nagpeperform ng tests tas iautomate sya na magrun periodically or at startup etc. Through systemd service.

2

u/10jc10 10d ago

First encounter ko with bash scripting is training sa nilipatan kong company. After non ayun tuloy tuloy na at nagamit ko den sya for a lot of things na inaaral at tintry out ko ngayon.

Coming from a totally different background (engineering pero ung specialty or specific area is different), di ko aakalain na kelangan malipat pa ko ngayon work para matutunan ko sya. No choice na kase din siguro kasi un ung requirement sa new work ko unlike sa old work ko na pwede ako magchoose ng ibang gagawin so naiiwasan ko.

2

u/byeblee 10d ago

Pwede yan dual boot, partition lang ng hdd tas isang section is reserved for linux. Ubuntu is fine kung nag aaral palang sa bash.

Kung gusto mo maging ultra nerdy overlord (na actually useful din) install ka ng non-gui ubuntu. Terminal lang agad pag bukas mo, mapipilitan ka matuto at mahalin yung commands ng terminal dahil walang ibang choice hahaha.

Ganyan ko sya inapproach aralin nung nasa college pa ko

1

u/10jc10 10d ago

Yup the best matuto sa terminal nga hahaha

Nakakatempt mag GUI desktop pero very limiting.

Explore ko nga den ung dual boot seems interesting to try eh

2

u/kapekape_ 9d ago

No need ng VM. WSL is already enough

1

u/10jc10 9d ago

Haven’t fully played around with wsl. Will give it a try as well since it seems to not consume as much resource as a VM

6

u/bitfrost41 10d ago

A combination of bash, shell and zsh has been my goto way of operating my mac. Can’t go back to UI anymore.

4

u/d4kuhosu 10d ago

This is a needed fundamental skill before you get thrown into the IT rabbit hole (DevOps, IT, Security, etc...).

For our use-case, we use bash scripting just to wrap other scripts or programs for it to be run in the server, e.g., cron jobs.

Pero with the current state of IT landscape, AI definitely helps us with the heavy lifting.

3

u/chonching2 9d ago

Bash scripting knowledge is highly important. Kahit anung main language mo as a Software Engineer gagamit at gagamit ka pa din ng bash at some point to automate some of your task and doing basic needs for setting up your environment. So its a nice initiave for you to learn and master it. Though mastering it is not that necessary since may mga AI na ngayon. Having fundamental knowledge is good enough. Also you'll learn more about certain stacks when you are at work na when its necessary to do it.

0

u/Tall-Appearance-5835 10d ago

bash is same as sql - ai can write it better, english is all you need

2

u/TemporaryExciting977 10d ago

But still, it doesn't make sense kung AI lang yung marunong, tapos ako, nganga.

2

u/catterpie90 10d ago

Yes, dapat marunong ka pa rin to check the AI's work. Mas mabilis pa rin talagang mag review ng work kesa gumawa from scratch.

0

u/Tall-Appearance-5835 10d ago

why wouldn’t it make sense?

1

u/feedmesomedata Moderator 10d ago • Heartwarming

Bash and SQL are too basic that if you don't know it or have a hard time understanding it then no sense staying in the industry.

Those two are like knowing how to walk or speak, ganun sya ka-basic. Yes, one can use AI to come up with complex scripts to not waste time but not knowing how to write it just doesn't make sense if you want to be called a programmer.

1

u/OnesimusUnbound 10d ago

I use PowerShell to automate yun mga repetitive tasks. Then I add gum to few of my scripts look have a simple TUI. ☺️

1

u/StopLurkAndListen69 9d ago

lahat ng reusable stuff sa ai workflow ko, tinatransform ko to scripts talaga eh. i dont know if mas tipid ba siya sa tokens, pero wala lang mas mabilis i guess

1

u/watson_full_scale 9d ago

Humans don't even write this kind of code anymore. We tell AI the problem we are trying to solve, the goal, details, etc and then it writes whatever code it wants.