Hacker News new | past | comments | ask | show | jobs | submit login

Right, but the fact that you can parse out something that didn't have a contract is a strength.

Someone had to write the Get-NetAdapter cmdlet to give you a contract, and Linux has those too, so a fairer comparison would be something like:

    addr=$(</sys/class/net/ens33/address)
I think that's just as readable as your example.

The question is how does powershell handle extracting something without a contract, and is that more readable than bash? I'm skeptical :)




> "Someone had to write the Get-NetAdapter cmdlet"

Amusingly no, nobody wrote it. There's a part of PowerShell which can wrap WMI/CIM classes into auto-generated cmdlets, and Get-NetAdapter is one of those. (Which is why it's not available on Linux installs of PowerShell).

Take a look at the XML in C:\Windows\System32\WindowsPowerShell\v1.0\Modules\NetAdapter\ and there's no C# code or .Net DLL for it, just "MSFT_NetAdapter.cmdletDefinition.cdxml" and "MSFT_NetAdapter.Format.ps1xml". Presumably auto-generated, human checked, though I can't prove that.

[1] https://docs.microsoft.com/en-us/previous-versions/windows/d...


Its not like pwsh can't do strings ffs. It just can do objects on top of that. You can totally go bash-like-crazy in it and parse strings if you like that.


Sure, I'm saying that would be a fairer comparison - getting output from something that has no defined interface.

So why not compare apples to apples, how would powershell extract the MAC from ifconfig output? If that's more flexible or powerful than bash with standard UNIX tools, then that might be impressive!


> how would powershell extract the MAC from ifconfig output?

It could go identically crazy as in bash, as it has its own grep (sls), can use grep itself etc.

    > (ipconfig /all | sls Physical) -replace ".+: "
    00-FF-84-14-66-D7
    00-FF-B7-06-19-0F
    00-15-5D-00-1F-3C
    ...


Right, that's a fairer comparison. So the question is, why is that better?


Its not. Everything else is.

Although, on more thought, it is better even as parsing engine as you have system design rules enforced across tools and OSes. Even single tool may work differently depending on *nix flavor.


Here's what I got:

ifconfig | ?{$_ -like "eth0 *"} | %{($_ -Split " ")[-1]}

In other words, find the line that starts with "eth0 ", then return the last column using " " as a delimiter.


But Get-NetAdapter just works. Your command, I don't have a /sys/class/net/ens33 on this Ubuntu virtual server. I do have a /sys/class/net/venet0 but /sys/class/net/venet0/address is blank, even though the VM does have an IP address.

Grepping everything under /sys/class/net/* can't find the IP in there. It shows up in `ip addr` as venet0:0 and as a P-t-P link, so I assume that's related; doesn't work unless you know the adapter name and still might not work then? What kind of "contract" is that?


Here's the output of the command the parent told me to run on my Windows workstation:

    > Get-NetAdapter -Name Wi-Fi | select -ExpandProperty MacAddress
    Get-NetAdapter : No MSFT_NetAdapter objects found with property 'Name' equal to 'Wi-Fi'.  Verify the value of the property and retry.                                                          
    At line:1 char:1                                                                              
    + Get-NetAdapter -Name Wi-Fi | select -ExpandProperty MacAddress                              
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                  
        + CategoryInfo          : ObjectNotFound: (Wi-Fi:String) [Get-NetAdapter], CimJobException
        + FullyQualifiedErrorId : CmdletizationQuery_NotFound_Name,Get-NetAdapter               
I know the problem, I don't have a wireless card on this machine, but how is this different from you complaining that your network interface isn't called ens33?


Even better than the ip | jq in my sibling comment.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: