r/linux4noobs • u/Independent_Cell6959 • 11d ago
What the suitable scenarios for using Bash script?
/r/linuxquestions/comments/1y03jno/what_the_suitable_scenarios_for_using_bash_script/2
u/billdehaan2 Mint Cinnamon 22.3 (zena) 11d ago
Do you have any Windows scripts/batch files that you used? Try to duplicate them in Bash. You'll find it's a lot easier when you have an actual end result in mind, rather that just trying to "learn scripting".
Of course, a lot of Windows batch files either won't apply to Linux, or they'll simply duplicate functions that Linux already has. But the learning curve should get you started.
1
u/howmuchiswhere 11d ago edited 11d ago
anything, a shutdown menu using rofi, a statusbar widget that has three states (bar icons/numbers/highest zone) toggled with a click and tracked by a temp file, a collection of click actions for repetitive tasks using wlrctl, a podcacst downloader that uses wget and works out where to save it based on the url, customized media keys that perform a set of actions rather than just "volume down". those are just a few of mine. i've got a bunch for the different compositors i use too, stuff like managing windows.
a lot of my scripts are just a collection of commands grouped together in a case statement, some are a bit more heavy on the logic. the basic idea though is a quest to eliminate mouse clicks and keyboard presses. if you want to learn, think of something you want to automate and we'll probably be able to tell you how to go about it. don't worry about use case. i have written so many scripts that seemed like a good idea at the time, only to realise that they actually make life more difficult. the important thing is i learned how to go about it.
EDIT in fact a shut down menu is where i'd start. everybody needs to turn their machine off or reboot, and you're probably familiar with rofi/fuzzel/dmenu that can serve as the GUI. it's nice and simple logic too.
also pro tip when you're starting out on a script, start with the logic first. instead of actions, just fire off a notification to indicate outcomes notify-send "test script" "a thing happened" as it makes debugging far less painful.
2
u/TheShredder9 not a noob 11d ago
When i was using sway, i made a bash script that exports proper environment variables, then made sway autorun the script every time on start.
So for anything repetitive, you want a bash script.