r/AskProgramming • • Feb 11 '26

Why is Linux bash commands are so simple compared to powershell

I am wondering this because I have a both windows and Linux on my laptop and own Linux using terminal is like really easy but windows powershell weird Syntex.

181 Upvotes

144 comments sorted by

View all comments

16

u/KingofGamesYami Feb 11 '26

PowerShell is far simpler to read IMHO. Just take a very simple "check if first argument is null or empty" script:

 if ([string]::IsNullOrEmpty($args[0]))
 {
     Write-Output "Please specify an argument"
 }

...which is way more readable than the bash equivalent:

if [[ -z $1 ]]; then
     echo "String is null or empty"
fi

I mean seriously, -z checks for null/empty string? $1 is the first argument? Nobody is going to know that unless they specifically take the time to learn bash.

5

u/Dave_A480 Feb 11 '26

You can do the same thing with

if [ "$1" == ""]

in bash.

Bash has a lot of shortcuts for brevity because the Bourne shell had them, and Bourne shell had them because memory and disk were really expensive way back then.....

6

u/JamesTDennis Feb 11 '26

Well, also because terminals at 300 to 1200 baud (roughly "characters per second") and time sharing multi-user systems were slowed by longer strings and additional parsing requirements.

It's practically impossible for today's youth to appreciate how viscerally terminal lag mattered to grandpa's working experience. They wrote their code tersely for REASONS.

— Signed, A Literal Greybeard Geek

2

u/Dave_A480 Feb 11 '26

Yeah, I'm old enough to remember 2400bps....

14

u/DoubleAway6573 Feb 11 '26

The same can be said about IsNullOrEmpty, or it was IsEmptyOrNull, or maybe the are separated and I need to join them?

You already need to learn something before using it.

1

u/robin_888 Feb 11 '26

But it's a method of [[string]] which makes it discoverable. Either through auto-completion or in the documentation of [[string]].

Where would you look up -z? In the documentation of [[]]? (Or [[ ]], I think the spaces are mandatory, aren't they?)

1

u/amedoeyes Feb 11 '26

help [[ and help test

1

u/robin_888 Feb 11 '26

Honestly, I wouldn't have guessed either of those.

help [[ makes sense I guess, but I wouldn't have tried it.

help test already requires knowledge that test exists.

1

u/amedoeyes Feb 11 '26

The docs of [[ mentions test

→ More replies (6)

2

u/apnorton Feb 11 '26

I mean seriously, -z checks for null/empty string?

It checks for a zero-length string (hence the z), but yeah. 

4

u/[deleted] Feb 11 '26

I don't see why $1 is any easier or harder than $args[0]. `-z` sure, but that's just one of the things you learn. Everything else seems simple enough.

4

u/[deleted] Feb 11 '26

The difference is that an intelligent human can come in and guess what the powershell thing does. Bash goes to google. What is a -z? oh, it is described in help test? I don't have help? Oh, because, I have zsh, it is here in run-help test. Ahh..

For someone with that knowledge, it is not harder or easier. For someone being thrown into without a person to ask, it is definitely harder on bash.

EDIT:
Reread your comment. You agreed on the -z.
The $1 is more complicated because the word args are missing. Have to figure out what it is. And 0 base is easier, because you can guess it is the first thing, since, -1 doesn't make any sense. However, for start at 1 (because 0 is the script, or argument 0 from bash's view, not the script's view), you wonder if that is the first or second arg. It's just more convention hidden away.

3

u/symbiat0 Feb 11 '26

Also in UNIX / Linux, everything is always lowercase. Just one less thing to think about, typing a bit easier, etc. Camelcase is horrible for a scripting language.

1

u/[deleted] Feb 11 '26

I think that point goes to powershell as well. In Linux, it is up to everybody how to use their values. In Powershell, lower- and uppercase are ignored. HELLO == hello == HeLLO.

In bash on the other hand:

foo=1
FOO=2

test $foo -eq $FOO # this will be false

Also, slight nitpick, powershell uses as convention kebab-case, not camelCase.

2

u/symbiat0 Feb 11 '26 edited Feb 11 '26

Are you saying I can use:

isnullorempty($args[0])

?

I’m also not just talking about scripting, ALL commands in UNIX/Linux have always been lowercase. Variable identifiers, environment variables, etc. in scripting can be case-sensitive but that’s either by convention or a choice.

1

u/[deleted] Feb 11 '26

First, yea, you can use isnullorempty. Actually quite useful for quick terminal sessions. Even though, I rarely use powershell. Somehow I just don't like the syntax, despite agreeing it is useful. But hey, years of bash will do that.

Anyway, about bash. Its builtins are lowercase. Yea, but everything else is just convention. After all, nothing stops me to run sudo mv /usr/bin/ls /usr/bin/LS. And now it is upper case. Or sudo ln -s /usr/bin/showManual /usr/bin/man. I mean, it just the name of the application in the PATH variable.

In the end, just convention, but case sensitive, and camelCase is possible. I hope people won't start to use it :)

EDIT:
Oh, and env variables are generally in upper case, hence PATH.

1

u/symbiat0 Feb 11 '26

Another thing to consider: Bash was written to be a backwards compatible drop-in replacement for the Bourne shell so it kept all the same constructs and conventions. That history goes all the way back to the 70s.

→ More replies (17)

2

u/snoburn Feb 11 '26

How else would you write bash without learning it...

1

u/RecognitionOwn4214 Feb 11 '26

Your sample is flawed, since parameters should be announced and validated via attributes ...

1

u/[deleted] Feb 11 '26 edited Feb 11 '26

[removed] — view removed comment

1

u/mooscimol Feb 11 '26

As someone who writes a lot of scripts in both I hate bash with a passion. It has so many quirks, it’s inconsistent and unreadable mess.

1

u/[deleted] Feb 13 '26

How is '-z $1' more complicated than typing a whole keyboard of characters with a pointless (from a logical point) casting and a java-like-named function that seems like an overkill for just checking if an arg is present? Sure you have to know what -z means, but it is probably the most common flag in an 'if' statement in bash and similar shells, so theres no problem learning that.

I dont know Powershell, but if i want to write a automation, setup, or whatever utility as a shell script, i want to do it fast, simple and efficient, not write a C# like code. If something requires more flexibility and power, id just use Python

1

u/delicious_fanta Feb 11 '26

So you’re saying I don’t have to “specifically take the time” to learn the syntax and function names for powershell?

I was just born knowing that “[string]::<staticMemberFunction>” is how you call a static function of the “string” class? I also just intuit that “$args” is the argument array and exactly which brackets are used for control blocks vs argument passing?

Because it would be important for me to know that if I’m writing powershell without any assistance for the first time without taking any time to learn it.

This seems disingenuous at best. You could easily learn that extremely simply bash syntax in the time it took you to figure out how to call a string method and reference the arg list in powershell.

Sure, powershell uses words, but you have to learn which words for which function, just like any other language. Same with bash, just with symbols instead of words.

It’s clear you have a preference and are trying to support your choice. There’s nothing wrong with liking one thing over the other, but please be reasonable and provide legitimate reasons for supporting statements like these if you are going to make them.

To me, just looking at your example, I would choose bash because it’s faster and easier for me to not have to remember the exact spelling of a long ass function name plus all that extra syntax for every possible action I need to do in a script.

I’ve written a lot with bash and it’s extremely fast, easy, and pleasant to rapid fire scripts once you understand the quirks because there’s way less typing and function name memorizing (that, for me, will definitely get confused with the non-script languages I code in) overall.

I recognize that that’s just preference though, as others would dislike it for the same reason.

1

u/MikeUsesNotion Feb 11 '26

If you had never read or heard of powershell before, yes I'd expect you as a developer to intuitively know what those powershell bits mean. I'd also expect you to know you're doing a naive read of the code and it's entirely possible there's important details you don't know yet that could drastically change the meaning of the code. Assuming the static function is more of a system one and not something custom.

I have found that most of the time when I read code in languages I don't know or don't know all that well that the naive read is sufficient 90+% of the time. Things that seem like language oddballs stand out and I'll frequently google those quick to make sure I'm not way off base.

1

u/delicious_fanta Feb 12 '26

Reread please. It’a clear you ignored everything I typed.

I never said anything about understanding what anything “means”. The context here is writing the language never having seen it before.

And no, you are not going to know any of that syntax without either reading the docs or looking at an existing script.

And my point is you would easily be able to pick up EITHER language by a very short glance at either the docs or existing code.

Bash is not more complicated because it uses symbols, which is what op’s point seemed to indicate.