r/linuxadmin • u/dimkoss11 • May 22 '26
A high-level language for scripting?
I usually use Python or C# for writing scripts, what are the disadvantages of this compared to use Windows Batch, PowerShell, Bash?
16
Upvotes
27
u/grumpysysadmin May 22 '26
If all you’re doing is running external commands with some minor logic, bash is fine. Once you start needing to do complex logic or handle complicated data structures, it’s worth moving to a more complex scripting language.
19
u/kavaunix May 22 '26
The main advantage of bash etc. is that it's universally available, even on bare-bones installs, and that it has less overhead (the python runtime will eat a couple of megs and that a few hundred ms to start up).
In most cases this is negligible, so just use what you're comfortable with. Python is definitely more readable. Personally I use bash for very simple scripts, but python for anything bigger.
13
u/Overall_History6056 May 22 '26
Nobody uses Perl no more?
5
u/ipsirc May 22 '26
I use lua btw.
4
u/Magneon May 22 '26
Syntax checking, type hints, and more robust support for things like testing are the main advantages of a scripting language vrs shell scripts.
Shell scripts are often a little quicker to write and test if you're familiar with the shell in question, but tend to become harder to maintain than say python if they are longer (at least for bash in my experience).
3
u/B0L1CH May 22 '26
Depends on what you want to do. Python is fine for most cases.
I like bash when doing a lot of stuff with files or awk when working with CSV files.
3
u/fubes2000 May 22 '26
Specifically bash can do some really impressive things that even high-level languages struggle to do simply or efficiently because of shell features like pipes, a rich ecosystem of GNU utilities, as well as being able to invoke any program with a robust command line interface.
Want to run some basic filters/analytics on millions of lines of log files?
sed,grep, andawkwill blaze through it in a minute. Sort those millions of lines?sortdoes it efficiently. Have a list of work that needs to be done?xargswill get it. Need to parallelize that?xargs -Porparallelwill do it.4
u/michaelpaoli May 22 '26
Is shell, e.g. bash, not high enough level for you?
Perl and Python are also high level, while also allowing one to go quite low level too.
(Microsoft) Windows? This is r/linuxadmin, why would we want to compare to that Microsoft sh*t?
9
u/aenae May 22 '26
You still need bash to run your script. Might as well write it in bash if it is a simple one
2
u/rairock May 23 '26
I'd never use C# for scripting. I think it's just overcomplicating things unnecessarily. Having Bash, PowerShell, Python and Go, at least in my case, you can cover everything you need to do in the world. I can't imagine a use case where you would need something not included on these 4.
1
u/gmuslera May 22 '26
Size matters. If it is simple enough and heavily dependent on calling other programs, handling pipes and so on a bash command line or script may be smaller, more intuitive and easier to maintain. There are scripts that are born from one liners with added requirements.
1
u/g_rich May 22 '26
Bash and Python when required.
Personally I’ve never used C# for scripting but I’m 100% Linux and Mac so I guess for those working on the Windows side C# / Powershell would be a thing.
1
u/Lammtarra95 May 22 '26
The main reason is so you can hand over your shell script to the rest of the team who do not know c#, lisp, or any other fancy language. Otherwise you get six months of job security and 10 years being stuck maintaining your unicorn script. Although nowadays we can ask AI to explain, translate or improve it so maybe it is less important.
1
u/stewie410 May 22 '26
At my work, I've been hard limited to:
Linux:
at -foccasionsWindows:
Given I'm both not a fan of Java, nor a Java dev, I will choose bash every time, unless Groovy makes a task significantly easier -- mostly because I'm most familiar with bash.
The right answer is to use whatever tool you're most comfortable with, that is most applicable to the task at hand.
1
u/adjunct_ May 22 '26
Object oriented
1
u/NL_Gray-Fox May 23 '26
If you hand me a bash, batch, powershell or python script, I can usually tell if it's safe to run. if you hand me something compiled (c#, Java, ...) I have no idea what it will do until I run it (even then you technically don't know).
e.g. uncompiled languages can be read by humans and are (in my opinion) therefor safer, plus if it doesn't work on my system because you hardcoded something that is somewhere else on my machine I can easily change it without getting the source code.
obviously there (are/can be) speed tradeoffs.
1
u/kentrak May 23 '26
Bash:
Perl:
Python:
Go:
I imagine C# is somewhat similar to Go but there's still a runtime to make sure is present, and I can't comment on PowerShell but it seems like an interesting language with how it passes structured data between shell components. Windows Batch? It will work in a pinch, and it's always present, but it seems fairly limiting.
1
u/john_crimson81 May 23 '26
python for anything with more than 10 lines of real logic, bash for quick glue and one-offs that need to run everywhere without installing anything. the runtime dep thing with python is a real concern on stripped-down systems but its not usually a blocker. c# is overkill unless youre already in a dotnet shop and want to reuse something. the actual rule is: use whatever you can debug at 2am without looking things up. bash looks simple but it has footguns that'll bite you in ways python just wont — unquoted variables, word splitting, exit code handling. most shell scripts i've inherited that were "quick scripts" were quietly broken in edge cases for years.
1
u/ReachingForVega May 24 '26
Python will work universally and when you work with async functions the minor delay starting is negligible. Instagram used Python for their backend until meta merged them in so it scales.
0
u/rankinrez May 22 '26
Somewhat a matter of taste. I’d pick Python over them all.
Bash is good for very simple ones
0
u/serverhorror May 22 '26
PowerShell is well integrated with Windows. That's it.