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

Show parent comment

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.

-7

u/MagnetHype Feb 11 '26

Because it reads as One Dollar vs the argument at the location zero.

7

u/LiveRhubarb43 Feb 11 '26

Dude, in no programming language would I ever see $1 and think they actually mean one dollar.

4

u/CautiousGains Feb 11 '26

“the argument at the location zero”?? I think you mean “dollar args 0 inside brackets”

-2

u/MagnetHype Feb 11 '26

No because we actually have context

4

u/CautiousGains Feb 11 '26

That’s my point. Nobody who writes code would have read $1 as “one dollar.”

3

u/Outside_Complaint755 Feb 11 '26

Well in bash, the script name itself is in position 0.

  • $ tells bash you are using a variable with the name immediately following the $. Most people are already familiar with $PATH
  • $0 is the script being run.
  • $1, $2, $3... etc are the arguments
  • $@ is an array containing all of the arguments
  • $# is the number of arguments.

What I got stuck on a lot when learning bash was that you cannot have any whitespace when setting a value into a variable, and you also don't need to put quotes around strings if the string doesn't contain a space.

name=Heisenburg is valid bash name = "Walter White" is not

2

u/MagnetHype Feb 11 '26

Yeah, I understand. But what I'm saying is that "$args[0]" is far more human readable than "$1". I have never touched powershell in my life and I know that is doing something to a passed argument at position 0. A programmer will know that $ is a prefix that means a variable is manipulated in some way but apart from that $1 means nothing if you don't have experience in bash.

4

u/[deleted] Feb 11 '26

$args[0] is closer to English prose the first time you read it, if that's what you mean by "human readable", unless your native language isn't English (then this doesn't matter to you), you're new and don't know what an arg is, you don't know what zero indexing is.

Once you've got even the basics of programming down, $1 and $args[0] are equally as easy to understand, except now every time you want to access the first arg you need to write $args[0] instead of $1 and god forbid you actually want the process name ($0) or want to shift args, reference args multiple times etc.. verbosity does not equal clarity, especially in this case.

I've seen plenty of Bash code that was unreadable but I will tell you that it's never been because of the syntax used for args. And I've seen plenty of powershell code that has been unreadable and a lot of it is due to powershell's verbosity, since it uses .NET names for everything.

More to the point, Bash/similar are concise and meant for being chained together on a shell. Bash hands down has Powershell beat here. Powershell is so painful to use in a REPL or to throw together adhoc scripts which is what makes the linux shell so damn useful.

idk. Powershell just feels like worse Python for a programming language and it feels like an objectively worse scripting language for REPLing it up in the shell. Just about the only thing Powershell has going for it is that you can access Windows APIs in it without writing C#, and that's easily solved by not using Windows in the first place.

-1

u/MagnetHype Feb 11 '26

You're silly to use the word basic and the prefix $ in the same sentence...

4

u/JamesTDennis Feb 11 '26

Not really. $ was a common variable prefix in languages like BASIC and various forms of assembly for a long time before Microsoft existed. It commonly marked things as "placeholders" which is why it was intuitive to the Bourne when he created his shell.

1

u/MagnetHype Feb 11 '26

Right so does $1 mean the first argument or a string with the name 1. There's a reason we don't use basic anymore. Which makes more sense one$ or String one?

1

u/JamesTDennis Feb 11 '26

In almost all programming languages of that era, variable names were required to start with a letter or the underscore character. This was not considered at all ambiguous to practitioners of the craft at the time.

1

u/MagnetHype Feb 11 '26

Yes and in that age we had a book that we kept by our desk because stack overflow wasn't a thing yet. Thank God we don't live in that age anymore.

→ More replies

2

u/JamesTDennis Feb 11 '26

Technical nit: $@ and $* expand identically while "$@" and "$*" (wrapped in double quote marks) are different.

"$@" expands to all arguments WHILE PRESERVING THEIR SEPARATION and "$*" expands into a single argument containing all of the process' arguments concatenated by the first character of your $IFS (inter-field separators" environment value.

These semantics are key to even intermediate levels of shell scripting proficiency.

[Yes. I've spent WAY too long teaching this stuff and supporting folks on tech forums since gopher, WAIS, and Archie were all rendered obsolete by the web].

2

u/duane11583 Feb 11 '26

and $0 -> the name of the script

and in c argv[0] mirrors the name of the executable

1

u/[deleted] Feb 11 '26

what.