9 ms·
Windows has a better shell. Practical example from a few days ago: here's feross' script to find compromised eslint-scope for Linux/Mac. find . -type d -n
by nailer 8y ago
Windows has a better shell.
Practical example from a few days ago: here's feross' script to find compromised eslint-scope for Linux/Mac.
find . -type d -name "eslint-scope" -print0 | xargs -n 1 -0 -I % sh -c "(cat %/package.json | npx json version) && echo '(at %)'"
Here's an equivalent for Powershell:
$results = @{}
ls -recurse -filter "eslint-scope" | foreach {
$file = "${_}\package.json"
$version = cat $file | convertfrom-json | select -ExpandProperty version
$results.Add($file,$version)
}
echo $results | format-list
Rather than scrape for regexs, you're using objects.Rather than using xargs to iterate, you're actually iterating. JSON is built in, you use 'select' to pick the property you want. Formatting is seperate from presentation.
You can use (and probably should) use Python on nix for similar cleanliness, but Powershell does all this and still feels like a shell. It supports emacs bindings (you use emacs binding on bash by default, regardless of which editor you use), readline, you have a profile, and all the good things you expect from *nix (Windows /terminals/ generally suck, but using the inbuilt terminal with groupy it's decent). It's just way nicer, at the expense of a little learning.
- cup-of-tea 8y agoPowershell doesn't feel like a shell to me at all. It's hideously inconsistent and somewhere between shell scripting and programming. You're right that Python is by far the better tool. Powershell only had to beat its incumbent, cmd, which is awful. Nobody would switch from bash/python to Powershell. Also, you can totally pipe into while in bash. There is no need to use xargs there. You can even deal with spaces in filenames if you need to...
- nailer 8y ago> Nobody would switch from bash/python to Powershell. I've used bash for 20 years, worked at Red Hat and IBMs Linux Group and my name might be in your OS. I switched from bash/python to Powershell. > It's hideously inconsistent How so? It's the only shell I've ever used where you can guess most commands. That's a massive achievement. > There is no need to use xargs there. Sure, I'd just use -exec and a fat lady. The example still shows the differences between - treating everything as strings then scraping with regexs and other string manipulation tools - using objects > You can even deal with spaces in filenames if you need to... A file name is an attribute of the file (inode/fileID). If you have to think about whether a file name has spaces or not you're scraping, rather than treating it as a single string-type attribute. This is why bash has a reputation for being brittle.