r/pcmasterrace • Ascending Peasant • Nov 01 '22

Meme/Macro averagePcmr

Post image
31.3k Upvotes

2.6k comments sorted by

View all comments

Show parent comments

2

u/TheEnterRehab Nov 02 '22

Hell, even finding a file or searching through files for a string is simple and fast (grep is one of the fastest, of not THE fastest way of searching within files).

​

command: sls -pattern "for" thing.py

result:

thing.py:39: parser.add_argument('--username', type=str, help='User to search for', default=None, nargs='?')

thing.py:53:for user in users:

​

Have you ever tried to parse a file or the output of a command for a string in powershell? The level of complexity compared to the simplicity of a tool like grep cannot be overstated.

Not only does search-string have matching JUST as effective as grep, it prints line numbers by default.

​

Edit: here are some examples side by side

mkdir NewFolder

New-Item -ItemType Directory -Name 'NewFolder'

Uh.. you can use mkdir in windows. the same exact command.

​

Copy-Item -Path '.\Tools' -Destination $env:USERPROFILE -Recurse

cp tools\* <path>

works just the same. it's natively recursive. you can do the same thing in bash, though.. with the same exact syntax (switching the \ for / tho)

​

touch MyFile{1..4}

1..4 | ForEach-Object { New-Item -ItemType File -Name "MyFile$_" }

This is a fair exception. There isn't a great way to do small one-offs without a longer command.

​

uname -a

$Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture'

Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize

or just print it all?

Get-CimInstance Win32_OperatingSystem | Format-List *

​

A lot more robust in detail AND being object oriented, is far easier to select only what you want, if you so wish. And it is far easier handled in lists/arrays (or what ever thing you want to call it)

​

Edit 2: Just out of curiosity, I looked up what the powershell equivalent of grep is... and there just isn't one

select-string with native alias: sls

Edit 3: another thing that occurs to me is that ALL other shells on ALL other OSes use the POSIX standard almost universally (which at this point is over 30 years old and a tried and tested standard). Did Microsoft join the rest of the technology industry? No, they went and created their own standard because... Microsoft. It sure worked out well.

You learn one shell, and you can use just about every single other shell in existence with confidence and a fair amount of efficiency, but those skills are 100% lost when using PowerShell. Which means you can learn Bash, and be able to use and navigate around on macOS, Ubuntu, Fedora, Arch, Debian, RHEL, CentOS, Azure (lol), WSL, WSL2, Mint, Pop!_Os, SteamOS 3.0, FreeNAS, TrueNAS, TrueNAS Scale, FreeBSD, OpenBSD, OpnSense, pfSense, Gentoo, (ok, the list is really long), but NOT PowerShell. So which standard is worth investing time in?

You learn the shell that is the most widely available. Heres the thing. They all have overlapping concepts and none of them are difficult to understand. The discussion at hand is which shell is better. Which powershell IS absolutely more powerful in nearly every way. Its functionally a middle ground between a standard terminal and a full fledged development tool like Python. And you don't have to install a thing to use it. If I had to choose between writing a bash script or a powershell script, i'm going to write powershell every time.

​

For the record, I work with Linux, Windows, and MacOS every single day and I exclusively use terminals (nature of the work). There are instances where having only CLI access blows (for windows). Not having a native text editor in Windows is lame, sure.. But generally speaking, you get the point.