Live data from Hacker News

A Saner Windows Command Line

futurice.com

101–110 of 164 posts

Re: A Saner Windows Command Line

#101
post #100
post #99

Earlier quoted context omitted.

Windows 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…

Simply 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.

Got 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 '_' ' ' *

Re: A Saner Windows Command Line

#102
post #67

> I know what you're probably thinking. One of the reasons you use Windows is so you don't have to use the command line. I know what I'm thinking. One of the reasons I don't use Windows is that its command line is a second or third class citizen.

Right. I don't understand how people get any real work done on a Windows machine.

What should take 2 seconds to type takes 20 seconds to find in godawful menus, that get harder and harder to find with each new version of Windows.

Re: A Saner Windows Command Line

#103
post #101
post #100

Earlier quoted context omitted.

Simply 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.

Got 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 s…

Dir | rni –NewName { $_.name –replace " ","_" }

That command does some extra stuff, which would make the bash equivalent also complicated.

Re: A Saner Windows Command Line

#104
post #86
post #72

Earlier quoted context omitted.

PowerShell objects are actually a superset of . Net objects. They can also represent COM objects, WMI objects, XML nodes, etc. You can also export them to CSV, XML, JSON, and yes, even text. If you have cygwin installed you can pipe to and from the cygwin commands from PowerShell and pipe to and from powershell.exe from your cygwin shell.

Languages are not the same, you'll never have interoperability; try exporting a .NET object with a 64-bit integer to be consumed by JavaScript, for example. Text wins.

PS C:\> 0x1234567812345678

1311768465173141112

PS C:\> 0x1234567812345678 >.\foo.txt ; cat .\foo.txt

1311768465173141112

PS C:\> "WScript.Echo('$(0x1234567812345678)')" >.\foo.js ; cat .\foo.js ; cscript //nologo .\foo.js

WScript.Echo(1311768465173141112)

1.31176846517314E+18

...

I'm not seeing your point.

Re: A Saner Windows Command Line

#105
post #66

Earlier quoted context omitted.

The first thing you should learn with PowerShell are the discoverability features: Tab completion, Get-help, get-command, show-command, get-member, get-alias. Last time I checked (and admittedly it's been a few years) bash has man pages and that's it.

Haven't used PS much – only used DuckDuckGo to find what each PS command meant, so it's possible I have misuderstood some, but – these are the bash alternatives, I think: | :PowerShell | Bash: | |Tab completion | built-in, OOTB| |Get-help | `help`| |get-command | `apropos -s .`| |show-command | ` --help` or `man `| |get-member | Inapplicable; text has a structure. Use `head -1` to find out, given structure is printed…

What's the bash equivalent of something like this?

Get-Command -Module SQLPS | ?{$_.Parameters.Values.ParameterType -contains [PSCredential]}

In PowerShell, this means "show me all the commands from the SQLPS module that take a credential object as one of the parameters".

Re: A Saner Windows Command Line

#106
post #101
post #100

Earlier quoted context omitted.

Simply 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.

Got 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 s…

"You obviously Googled as well as your code got it backward. " - No, just a simple mistake from writing it on the fly.

This isn't even probably the smallest, somebody smarter than me could do better.

There's probably a PowerShell module that has your equivalent.

Re: A Saner Windows Command Line

#107
post #85

Earlier quoted context omitted.

Googled "powershell ironpython" and got this[0] as first result. Before that, I was going to point out that IronPython, despite it's performance issues and nitpicky differences (there's no 'struct' module, but there's '_struct', which is... struct and they somehow forgot to rename) is still considered a .NET language. If there's anything wrong with the article (for one thing, it's 4 yo), please point it out. I just b…

You're missing my point.

Could you please be more explicit about it then?

The part about the .NET objects has already been addressed by others, and I actually like that -- right now at work we're wrestling with a few command line applications that output text (in full UNIX-style) and it's a mess to parse the thing, because it's so badly documented. If we had objects as a result it'd be glorious (not that PS would help, this isn't a bash script we're working with/against).

Re: A Saner Windows Command Line

#108
post #84

Powershell and its long winded cmdlets are really hard for me to like. I always fall back to cygwin on windows. I once wrote a PS script to set some power management options on a corporate laptop. The script was 11 lines long (vs 3 lines in Python), it was harder to read and understand. Even with ISE available it was much harder to write. I followed along with some exchange server tutorial where the prescribed easy w…

PowerShell obeys the first iron law of I/O: ALL data has a type. Bash (and Unix in general) -- does not. Now of course the implementation of typed pipelines in PowerShell is clunky and forced, because typed I/O primitives do not (yet) actually exist in Windows, so all the piping is done within one process with streams of object pointers, else it doesn't work. There are other problems, too: I recall one advocate linki…

And the UNIX style has a cost: It is insecure e.g. [0][1].

Luckily modern UNIX-based systems are rarely used as multi-user terminals these days or we would see many more privilege escalations via exploiting bugs in scripts which iterate over user owned files. Even in web scenarios, most web frameworks carefully manage what is allowed in a filename or set the filename themselves.

Ultimately because on UNIX there is no type, you have to make assumptions. These assumptions are sometimes dangerously wrong. You can definitely write scripts and execute commands in a more secure way, but you can go google Linux tutorials right now and find tons of examples where newbies are taught to do it wrong out of the gate.

Data types make this "secure by default." String for everything requires the script-writer or command line-writer to be perfect every time they hit return.

[0] http://www.defensecode.com/public/DefenseCode_Unix_WildCards... [1] https://www.helpnetsecurity.com/2014/06/27/exploiting-wildca...

Re: A Saner Windows Command Line

#109

Earlier quoted context omitted.

I agree with you (was about to post something similar), and wanted to add that some unix commands (which become part of the soul of bash scripts), are sometimes named in weird, unintuitive ways. For one thing, one potentially dangerous command is simply called "dd", and its man page[0] says next to nothing at all about its true power, uses and danger. [0] http://linux.die.net/man/1/dd

I don't think it's dd itself that's dangerous, rather the fact that it's usage is often paired with root access to raw device nodes on the filesystem. Even innocuous things like tee, cat, and bash output redirection can mess up your system if you blast something into /dev/sda.

Indeed, without root access you don't get to screw a disk with dd. But let's also admit that saying dd is a tool for copying files is a bit like saying that with a katana sword you can slice pizza... Technically true, but you're likely to get hurt in the process.

Re: A Saner Windows Command Line

#110

Powershell and its long winded cmdlets are really hard for me to like. I always fall back to cygwin on windows. I once wrote a PS script to set some power management options on a corporate laptop. The script was 11 lines long (vs 3 lines in Python), it was harder to read and understand. Even with ISE available it was much harder to write. I followed along with some exchange server tutorial where the prescribed easy w…

This will help with longwinded'ness

gal * | more

A whole list of short alias's

Post reply on HN