r/PowerShell • u/[deleted] • Nov 28 '21
Bash vs PowerShell Cheat Sheet
https://blog.ironmansoftware.com/daily-powershell/bash-powershell-cheatsheet/5
Nov 28 '21
This is not how you concatenate strings in bash. Also, you don't use double quotes on the variables during echo, which is advised.
And how come you're using normal intendation on the powershell code, but potato-intendation on the bash code? Any particular reason?
And why do you create the "make directory" in bash inside of a subshell, but in the powershell code you create it in the same process?
I mean, your article is a quick and dirty starting point, sure. Better than nothing.
But for publication to the rest of the world it's apparent that you have to polish it... a lot.
2
u/BlackV Nov 28 '21
you talking about
`mkdir $newdir`it think the back ticks were editor leftovers
2
Nov 28 '21
I don't think so.
2
4
4
Nov 28 '21
Those are terrible examples of While Loops. Rather than use break to get out of the loop, you should be setting the sentinel to a value that stops the loop at the while () condition test. In the case of the bash loop, you should be setting $valid to false so it stops on the next condition check, and the Powershell version is a infinite while loop, which are usually considered a special subset of While Loops.
3
u/fuzzylumpkinsbc Nov 28 '21
Looks good, I'll save it to do the reverse, kinda wanna learn some basic bash
2
u/jsiii2010 Nov 29 '21
I prefer "add-content" over ">>" for appending to a file. >> appends in utf16 format, and doesn't check what the current format is, so it can mix utf8 and utf16 in the same file.
1
u/MonkeyNin Mar 22 '22
Yep. Using
>>inWindows Powershelldoesn't care what the file's encoding isUsing
>>Inpowershelldefaults to utf8This config will help mitigate most of the crazy encoding defaults in windows powershell.
1
u/toast-gear Nov 28 '21
Why is the powershell indented but bash isn't, no one writes bash scripts like that.
13
Nov 28 '21
[removed] — view removed comment
6
u/sotonohito Nov 28 '21
Eh, while I'm not fully on board with the more verbose structure of powershell autocomplete takes a lot of the sting out.
0
16
u/wtgreen Nov 28 '21
Write-host is not the equivalent of echo... write-output is.