+ 2

When Should you use bash script rather than another programming language such as c++ or python?

Are there certain things that bash script can do that are difficult to implement in other languages? What can it do that other programming languages cant?

30th Aug 2019, 9:51 AM
Logomonic Learning
Logomonic Learning - avatar
13 ответов
+ 9
In my experience bash shines when we wish to do small things such as. - Automating some tasks like file/folder creation, setting permissions. - scanning folders and files - operating other softwares - interacting with OS - chaining operations But when task at hand grows big or demands some sort of generalization and I see a lot of variables then the practicality aspect of Bash script gets diminished and it gets harder to maintain. In those situations a python, perl, node, C/ C++ codes are much more practical. Although Powershell in windows is a different beast. Since it's built on top of .NET framework we operate the data as objects and have access to all the methods. Resulting script has more control. Unlike bash where every output is string based. One might also fell in love with the Powershell's ISE( integrated scripting environment) in windows that accelerates learning a lot. Coming back to main question, I ll look into those specific scenarios. It's an interesting question. Will need to research.
30th Aug 2019, 3:39 PM
Morpheus
Morpheus - avatar
+ 9
Shell(bash) by itself isn't that useful. It's the entire ecosystem, tools & commands that come handy which are. For high speed data processing, shell tools can sometimes be better than writing code in scripting and similar languages, without losing the developement speed & simplicity of them. e.g, here: https://adamdrake.com/command-line-tools-can-be-235x-faster-than-your-hadoop-cluster.html Writing short commands is another or the main benefit. You can also call the shell and related commands from your program, so it's not like you loose anything here.
30th Aug 2019, 4:30 PM
Lord Krishna
Lord Krishna - avatar
+ 5
If you are on linux you sometimes have to use bash. init-scripts in /etc/init.d that run when the system starts come to mind. (But maybe I'm wrong and you can run other scripts there? I've never tried) Apart from that it's also useful for quick one-off scripts. Maybe you want to crunch 40 megabytes of logfiles or configure your ethernet adapter or who knows what. What's also cool is that bash is available on any Linux distro out of the box (and also mac I guess and also also Windows soon, so, uh, everywhere?)
30th Aug 2019, 1:18 PM
Schindlabua
Schindlabua - avatar
+ 4
Schindlabua windows soon! I’ts not surprising, windows uses linux for cloud infrastructure and has paid Linux $500K. I’m aware that you can use some bash commands in windows via git-bash but it’s nowhere near the real functionality of the real thing. will be any different from git-bash
30th Aug 2019, 1:23 PM
Logomonic Learning
Logomonic Learning - avatar
+ 4
You can already install the linux subsystem! I forget if you still need to opt-in to some windows beta in the windows update settings, but you can then enable it in the windows features dialog. I have it on my PC but I'm ashamed to say I haven't needed it much yet. BUT microsoft is working on a better windows terminal (microsoft/terminal on github, you can already download it for w10), which apparently integrates the linux subsystem much better. Exciting times lie ahead for sure!
30th Aug 2019, 2:26 PM
Schindlabua
Schindlabua - avatar
+ 3
Martin Taylor Thanks for mentioning the AWK utility. I’ts this kind of insight that makes SL a great place to learn new things👍
3rd Sep 2019, 9:18 AM
Logomonic Learning
Logomonic Learning - avatar
+ 2
Ace you mean like accessing information from a database or data mining?
30th Aug 2019, 2:41 PM
Logomonic Learning
Logomonic Learning - avatar
+ 2
you mean to say you can do with Bash everything you can do with a language like php? Now it all makes sense. Is it possible to use bash alone for backend stuff? Or would it be just for a limited number of things?
30th Aug 2019, 3:07 PM
Logomonic Learning
Logomonic Learning - avatar
+ 1
I recently tried to generate html tags with batch, but it couldnt remove the quotes from the html tags. I have a feeling that I could easily perform a task like that with bash
30th Aug 2019, 3:35 PM
Logomonic Learning
Logomonic Learning - avatar