5 ms·
To hear bash-people to call Powershell "non-intuitive" sounds like those immigrants that go to a foreign land, refuse to learn the local language and insist on
by diego_moita 11y ago
To hear bash-people to call Powershell "non-intuitive" sounds like those immigrants that go to a foreign land, refuse to learn the local language and insist on the natives to understand their immigrant language. Or like programmers that think that every programming language should have the C syntax.
Bash and Unix commands are only "intuitive" after years of practice; Powershell is not different. And it doesn't have any obligation of being equal to bash.
- tacos 11y agoWindows fanboy here. Powershell made the mistake of combining a bad command prompt with a bad scripting language. It is not a "shell" at all. It is bad Python. The excessive verbosity and object safety is great for admin scenarios where you don't suddenly destroy your corporate email transition because of a VP with an apostrophe in her name. But at that point perhaps you should just use C# instead? But for everything else it just looks nuts to outsiders. That's why even the MS developer groups are releasing command line tools cross-platform that behave like Unix apps, not PS monstrosities. https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/ https://azure.microsoft.com/en-us/documentation/articles/xpl... Powershell should be a feature that draws people from AWS. Instead it is seen as a drawback, even inside MS.
- UK-AL 11y agoSimply stating something is bad, without anything to back it up, doesn't make it bad. Learn some alias's if you don't like the Get-X style of functions. gal * | more Will list tons of alias's for you.
- tacos 11y agoGot a directory full of files with underscores in the names? Want spaces instead? Easy, type this: dir -recurse | where {-Not $_.PsIscontainer -AND $_.name -match "_"} | foreach { $New=$_.name.Replace("_"," ") Rename-Item -path $_.Fullname -newname $New -passthru } EDIT: I purposely posted the first Google result. You obviously Googled as well as your code got it backward. But really, why isn't it this? It's worked since the 1980s. You'll dig it since it uses extra apostrophes. rename '_' ' ' *
- UK-AL 11y agoDir | rni –NewName { $_.name –replace " ","_" } That command does some extra stuff, which would make the bash equivalent also complicated.
- latkin 11y agoYep. Technically the request included recursive rename, and to avoid renaming directories, but gosh that's not hard: dir -rec -file | rni –newname { $_.name –replace "_"," " } Edit: Oops, request did not include recursive, the original sample solution did. FWIW top Google results for "unix recursively rename files" give below solutions (slightly different scenarios but you get the idea). Not particularly shorter, or less cryptic: find . -iname "*dbg*" -exec rename _dbg.txt .txt '{}' \; shopt -s globstar nullglob rename _dbg.txt .txt **/*dbg*
- tacos 11y agoY'all are still missing the point. We live in a world where people use CoffeeScript to avoid typing a semicolon. When you Google a PowerShell problem the Google results come back looking insane. You can play code golf here all you want but even this version looks nuts to outsiders. It's a cultural problem. You don't solve it by shouting subtly-differing versions of your culture, louder.
- UK-AL 11y agoHis 'rename' wasn't recursive. <Quote>Y'all are still missing the point. We live in a world where people use CoffeeScript to avoid typing a semicolon. When you Google a PowerShell problem the Google results come back looking insane. You can play code golf here all you want but even this version looks nuts to outsiders It's a cultural problem. You don't solve it by shouting subtly-differing versions of your culture, louder. ".</Quote> You're not getting the point. Powershell is just short, and sometimes shorter if you actually learn it. "When you Google a PowerShell problem the Google results come back looking insane" - This is a problem with the age of powershell. Bash has been around for ever, so there is lots of good quality content on the web.
- 11y ago
- maxxxxx 11y agoIn my view they should have made Powershell as a language that's derived from C#. Or they should have stuck to bash. Both approaches could have worked. Instead it's that weird thing in the middle that doesn't do anything really right.
- thoth 11y agoThings I like about PowerShell include objects - cmdlets return them and you can call methods. For example, you can get a list of services (get-service) and each is a ServiceController object, which you can Start(), Stop(), etc. Things I don't like, or is a pain point for me, are those same objects. As far as I can tell, there isn't a better way to figure out what you actually are getting back from a cmdlet besides feeding output through Get-Member. For example, what comes back from dir/ls/Get-ChildItem? Well that's a trick question because it depends on which "provider" you invoke. On a file system (dir somedirectory) you'll get back FileInfo or Directory info, for a registry hive (dir hklm:) you'll get a RegistryKey, for environment variables (dir env:) you get a DictionaryEntry, etc. So while it is fantastic there is a general way to enumerate items, the docs have to be vague and list System.Object as what returns from Get-ChildItem and its various aliases, which isn't very useful for working with the results. This makes forming non-trivial commands with pipelines fairly annoying because I have to feed each stage through Get-Member to even figure out what I have and what is now available; this strategy starts to break down if a pipeline stage feeds a loop, etc. I'd love it if the ISE displayed what actual object type exists at every point of a pipeline, rather than the trial-and-error-by-Get-Member approach I've adopted. Or for there to be some better way to get the return type of a cmdlet. PowerShell is a huge improvement over the old command prompt though.
- 13of40 11y ago> what comes back from dir/ls/Get-ChildItem? If you look at the note properties that get added to the objects, they're consistent across providers: PS C:\> (Get-Item c:\).PSPath Microsoft.PowerShell.Core\FileSystem::C:\ PS C:\> (Get-Item env:username).PSPath Microsoft.PowerShell.Core\Environment::username PS C:\> (Get-Item HKLM:\software).PSPath Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software There's also some magic that you can do with tab completion to see the properties. For example, if you type... (Get-ChildItem c:\ | sort). ...and hit tab, you can tab through the list of properties of the objects returned by Get-ChildItem when it's used on the FileSystem provider. (Don't ask me how the hell that works, though...)
- brudgers 11y agoI am a big fan of Powershell, yet...and there had to be a "yet", now didn't there?...the Bash based criticism is well grounded even if not always perfectly articulated. I see it this way, the great thing about Powershell commands is that I get back an object. The great thing about Bash commands is that I get back text. The object is great because I don't have to parse it. The text is great because I can parse it. The downside of Powershell is that if I don't have technical expertise in regard to the object a command returns, I have to go read deep into a manual to figure how I can do something simple. The downside of Bash is that if I have deep technical expertise about the text that is returned, I still have to parse it as text to do something simple. The high level abstractions of Powershell are better suited for dealing with known processes and contexts where I care about the semantics of the returned value. The low level abstraction of text is better for dealing with unknown processes and contexts where I don't really care about the semantics of the value.
- aembleton 11y agoI've never used Powershell. Is it possible for Powershell to output the object as JSON so that you can see what you can read from the object?
- kuma4 11y agodir | ConvertTo-Json dir | ConvertTo-Html dir | ConvertTo-Xml dir | ConvertTo-Csv
- brudgers 11y agoIn the world of Powershell, reflection would be the way to go because then I still have an object. A rough analogy would be the window object in Javascript where I call `window.open(something)` directly. Serializing a value returned by a Powershell command to JSON eliminates being able to call `returned_value.some_method(something)` because converting it into JSON puts me in the world of text and parsing. At that point, I either know the name of the method I'm looking for or I don't. In the first case the conversion to JSON doesn't do me any good because I can just call the method directly using `object.method(value)`. In the second case, it doesn't do any good because I don't know the method I want. Reflection looks more like this: http://stackoverflow.com/questions/9952391/use-get-member-for-reflection http://stackoverflow.com/questions/9952391/use-get-member-fo...
- chm 11y agoI've just recently gone back to using Windows 10 after being a heavy XP user. I think Powershell is perfectly fine... for my uses up to now there's always a tutorial online to help. And some commands are the same between shells so I wasn't completely lost :/