News for hackers. Stuff that matters.
Re:New Windows 10 Devices From Microsoft by Karunamon on Tuesday October 06, 2015 @02:40PM (#10341289)
Hence "I can think of". That was copypasta from an internal wiki. I don't appreciate being accused of "disingenousness" from an off the cuff example.

By the way, your example is precisely 12 characters longer than mine and still multiple times shorter than the equivalent PS, so if your goal was to somehow disprove PowerShell's annoying verboseness rather than snark at me, you failed.

Re:New Windows 10 Devices From Microsoft by Someone1234 on Tuesday October 06, 2015 @02:51PM (#10341379)
> I don't appreciate being accused of "disingenousness" from an off the cuff example.

Then check your examples before you post them to make a specific point. It is a point of fact that calling those two things "analogous" is incorrect, and your offense doesn't change that fact.

You also specifically said "I can think of" implying that you created the examples rather than that you got them from an "internal wiki." The fact that you said you thought of the UNIX example gives me solid ground to describe the created example as disingenuous.

I cannot help it if you're being misleading about how your got your examples.

> By the way, your example is precisely 12 characters longer than mine and still multiple times shorter than the equivalent PS, so if your goal was to somehow disprove PowerShell's annoying verboseness rather than snark at me, you failed.

My point was your examples were poorly constructed and misleading. I proved my point I believe. The difference between my accurate example of PS and your inaccurate example are night and day.

I'll leave it up to the reader to decide if PS's syntax is more to their liking. I just think they should start off with accurate information so they can form an accurate determination themselves.

In other words I won't get drawn into comparing my PS example with your UNIX example. I just want both examples to be truly analogous of one another.

Re:New Windows 10 Devices From Microsoft by Arnavion on Tuesday October 06, 2015 @03:34PM (#10341701)
>By the way, your example is precisely 12 characters longer than mine and still multiple times shorter than the equivalent PS

I think you didn't realize, but what Someone1234 has there is the equivalent PS, not UNIX shell.

Re:New Windows 10 Devices From Microsoft by togusa on Tuesday October 06, 2015 @02:45PM (#10341332)

    (iwr "http://Slashdot.org").Links | select href
Nearest Unix equivalent please.
Re:New Windows 10 Devices From Microsoft by qznc on Tuesday October 06, 2015 @05:44PM (#10342635)

    lynx -dump -listonly http://Slashdot.org
Not exactly, but close. Needs more work if you want to pipe it further.
Re:New Windows 10 Devices From Microsoft by kuschku on Tuesday October 06, 2015 @03:31PM (#10341685)
What does that even do? Sorry, I’m not familiar with Windows, but would love to provide a unix equivalent.
Re:New Windows 10 Devices From Microsoft by Arnavion on Tuesday October 06, 2015 @03:43PM (#10341759)
Fetches http://Slashdot.org (`iwr ...`), parses it as an HTML page and extracts all the anchor tags (`.Links`), and selects the href of each anchor tag (`select href`). Since this is the end of the command, the hrefs are returned and printed as an array of strings (so one href on each line).
Re:New Windows 10 Devices From Microsoft by socksy on Tuesday October 06, 2015 @03:43PM (#10341762)
Including the href="" bit?
Re:New Windows 10 Devices From Microsoft by Arnavion on Tuesday October 06, 2015 @03:46PM (#10341781)
Just the values. The same things you'd get by accessing the href property in JavaScript.
Re:New Windows 10 Devices From Microsoft by socksy on Tuesday October 06, 2015 @05:15PM (#10342458)
Well, with just grep and curl, it'd be something like:

    curl http://slashdot.org/ | grep -o "href=[\"'][^\"']*" | sed -e "s/href=\"//"

But presumably this is being discounted due to the lack of HTML parsing, so not the same as the Powershell example. Then one somewhat ugly method would be using the html xml utilities provided by the W3C and available on most package managers:

    curl http://slashdot.org/ | hxpipe 2> /dev/null | grep Ahref | sed -e "s/Ahref CDATA //"
Obviously not as pretty, but it does do a nice job of going through the HTML tree, and doesn't rely on nicely formed XML that /usr/bin/xpath would.
Re:New Windows 10 Devices From Microsoft by Arnavion on Tuesday October 06, 2015 @05:27PM (#10342536)
Yes, a naive grep will pick up variables named href in JS, the text content of a div that contains "href", an href attribute on a non-anchor element, etc. so a utility that specifically parses HTML is necessary, but not sufficient.

I'm not sure how robust your hxpipe example is against those.

Re:New Windows 10 Devices From Microsoft by socksy on Wednesday October 07, 2015 @06:32AM (#10345180)
It's a shell script. If you're architecturing more than that in your shell script, I would suggest that you shouldn't be doing this in a terminal in the first place. And if you're just trying to click links for a quick shell script, why not just do it via wget in the first place, rather than have this intermediate list of strings?

But since you asked, hxpipe assumes that href on a non anchor tag is an error and should be represented as an Ahref... which isn't too bad an assumption to make, tbf. The other situations is dealt with (text content, javascript).