9 ms·
I'm always in favor of things being open-sourced, but I do kind of wonder in what universe I would use PowerShell when Bash is readily available.
by tombert 10y ago
I'm always in favor of things being open-sourced, but I do kind of wonder in what universe I would use PowerShell when Bash is readily available.
- xyzxyz998 10y agoWhat do you know about Powershell? (The answer will depend on that)
- UK-AL 10y agoHonestly, I prefer the object based approach compared to the text wrangling approach.
- larrik 10y agoAs a full-time Linux user, I have to say that bash is overrated. For instance, on Windows I could press the up arrow through my history 20x to find a group of commands I want to run, press Enter, then press DOWN for the following command, then enter, then DOWN until I run them all. In Bash, I need to press UP 20x every single time. Yes, you can customize it a lot, and you can script it but default bash isn't that special to me.
- soperj 10y agoOr just be sane and use ctrl-r and search.
- feld 10y agoI get the feeling that most users have only accessed 5% of the features available in their unix shell of choice
- emgee3 10y agoI would say not just the shell but most software
- fapjacks 10y agoAnd almost certainly languages, too. For example C++.
- npsimons 10y agoAs someone who has created templated subclasses with both private and public virtual inheritance, I don't think that's a bad thing. C++ is wildly powerful, but it's a mess, and most people should stick to easily understood idioms/patterns, for the sake of maintenance if nothing else.
- nitrogen 10y agoI also highly recommend enabling the pgdn/pgup bindings for history-search-forward/backward. If you are searching for a prefix it's a bit easier than ^R.
- pvdebbe 10y agoI bound these under C-n and C-p. Very convenient indeed!
- larrik 10y agoI do use this too.
- lmm 10y ago> For instance, on Windows I could press the up arrow through my history 20x to find a group of commands I want to run, press Enter, then press DOWN for the following command, then enter, then DOWN until I run them all. In Bash, I need to press UP 20x every single time. I think the Bash default is better here. If I wanted to run 20 closely related commands, I would make them a single line; far more commonly I want one command from 20 commands ago and then the last command, which is a pain to do on Windows. Much worse is that Windows seems to lose all history every time I close and reopen a command window.
- SixSigma 10y agoBash is awful. But so are shells in general. Even Rob Pike says as soon as your shell program gets longer than a few lines, write it in a proper language.
- clebio 10y agoCitation please? I would love to share this with some of my coworkers.
- SixSigma 10y agoI can't find it anywhere, I have tried. I think it is in the plan 9 mailing list - 9fans, as that is where I have interacted with Rob
- satysin 10y agoI feel that principle is true from all high-level languages as you move down the chain. Shell scripts should be 1-20 lines. Python/Ruby/whatever for 20-100 and compiled for anything >100.
- jamespo 10y agoWhat if you use Nuitka or PyPy for Python, does that magically allow you across the arbitrary border?
- mikestew 10y agoI was about to refute you with a recent example of mine that just needed to serially execute a bunch of commands, and it's well over 20 lines. Then I remembered that I needed to introduce some branching logic, said "not in bash, I'm not", and rewrote it in Python. So for me, it's not a matter of LoC but complexity. Need to copy file from here to there, then commit to git repo, blah, blah, blah, then kick off a build? Whether it's a 1000 lines or 2, I don't have a problem with doing that in bash. But as soon as I need some logic (or on rare occasions, perf), I go to something else. Given that, why do you cut shell scripts off at 20 lines? I ask in the spirit of being open to the possibility that maybe I'm doing it wrong. :-)
- Spivak 10y agoIt seems weird that the feature of PS that you're most impressed with is something so... trivial? You have full access to your history in both shells so you could easily emulate that feature in bash/zsh or you could create a special binding to run all commands from a point in your history so you only have to press Enter once.
- larrik 10y agoI actually think the basic windows command line that does it, as I was never in the habit of installing PS while on Windows.
- deleted 10y ago[deleted]
- cstross 10y agoBash is 27 years old. It was written to replace the Bourne shell, which is 39. It is not terribly surprising that a 9 year old tool like Powershell made some improvements over an earlier tool that was already old enough to vote!
- lottin 10y agoThe bash I'm running is actually 3 years old. You make it sound like bash was written 27 ago and no one has touched it since then. Secondly, what constitutes an improvement is a matter of opinion. For example, I don't see this Powersell as an improvement at all.
- ktRolster 10y agoAutocomplete in Bash was actually a revolutionary improvement
- jodrellblank 10y agoAnd autocomplete in PowerShell is again. Cmdlets tell the shell their parameters, and their parameters are long names, so you can just tab through them to find a) the available parameters and b) the ones which might help you.
- Sylos 10y agoWell, it's not an improvement, it's just a different design-choice. I for example much prefer Bash's way of doing it. Also, Bash does have a way of doing it the Powershell-way, if you want that, as others have commented. Which is also why I disagree with your statement. Bash may be old, but neither the underlying technology nor the use-case changed much in that time. So, there is not a whole lot where you can innovate with a new tool, at least not for such basic tasks, and instead, Bash has matured throughout 27 years to perfectly fit that underlying technology and use-case that millions of people have.
- ldiracdelta 10y agoI don't see a tremendous amount of accumulated wisdom in Powershell. It may be newer, but I'm not sure they looked at prior art or had design members who were shell gurus in any other shell than `cmd.exe`, which is a horrific shell. Why are commands horrendously long in powershell? If you spend time in the shell, you don't want your fingers falling off due to overuse. Aside... one of the design decisions Microsoft took that absolutely blows my mind is using `\` for file hierarchies instead of `/` when you're writing an operating system in C!
- pm215 10y agoYou can use control-O for that, which does "execute this command as if I pressed enter, then when it's done bring up the following command in command line prompt". So if you have a set of commands to run that are 20 lines up in history, you can first find them (with 20x UP or by reverse-search), then just control-O control-O control-O control-O ... to execute them one after another.
- petepete 10y agoI wasn't aware of this. Thank you. Not that I've been using Bash and zsh every day for twelve plus years...
- mikestew 10y agoTwelve? Youngster. I'd guess I'm coming up on thirty years. And I did not know this. Now the trick is to remember it next time the need comes up. :-)
- deleted 10y ago[deleted]
- verbify 10y agoSeems to be an instance of Cunningham's Law: https://meta.wikimedia.org/wiki/Cunningham%27s_Law https://meta.wikimedia.org/wiki/Cunningham%27s_Law
- tbrock 10y agoOh. My. God. Life changing! Out of curiosity, how did you discover that you could do this?
- pm215 10y agoIt's been something I've used for many years, so I really don't recall any more just where I found out about it...
- 10y ago
- egwynn 10y agoIn many bash configurations, ctrl-o is bound to 'operate-and-get-next’. If you hit up 20x, you should then be able to hit ctrl-o to run that command, and your history will automatically go to the next command down. Check it out, it’s great! EDIT: beaten by pm215!
- ldiracdelta 10y agoIf you put this in your `~/.inputrc` [1]: "\e[A": history-search-backward "\e[B": history-search-forward "\e[C": forward-char "\e[D": backward-char you can start typing a previous command and go up through your history for all commands starting with whatever you currently have typed into the bash shell. Reset the scrolling through the history with `ctrl+c`. Personally, I hate that powershell remembers your position in the shell history. I don't want to maintain a mental model of the shell history rollodex and where I am in it. That's one less part of my brain that I can't use for thinking about the code. If I have a set of commands to type over and over: history 20 | head -10 | sed -r 's/^ *[0-9]+ *//g;' > new_script.bash * [1] http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/ http://codeinthehole.com/writing/the-most-important-command-...
- larrik 10y agoI think I tried something like this once before, and it broke something else. I can't remember what that was, so I'm totally trying this.
- larrik 10y agoYeah, this breaks the "move over by word" with Ctrl+Left and Ctrl+Right which I use a lot. Maybe I need to add them explicitly.
- ldiracdelta 10y agoAh. I use the standard emac'esque commands to move over by word. alt+b for back word, alt+f for forward word. Not at all intuitive... windows line movement commands win over emacs bindings form an intuitive perspective. Also you don't need these to get up/down to work: "\e[C": forward-char "\e[D": backward-char Those are for left/right arrows.
- deleted 10y ago[deleted]
- lottin 10y ago
- njkanjsd 10y agoIt's just default behavior and its customizable for a reason. Different people have different preferences, powershell's default behavior is in no way 'better' than bash's. You can also use a different shell like zsh.
- ThatGeoGuy 10y ago>For instance, on Windows I could press the up arrow through my history 20x to find a group of commands I want to run, press Enter, then press DOWN for the following command, then enter, then DOWN until I run them all. In Bash, I need to press UP 20x every single time. I know other users have addressed this issue in other comments with solutions, but you do know this isn't an issue with Bash so much as it is with readline, right? There are plenty of ways to customize readline/inputrc to make it do what you want. There's even linenoise, if you hate readline for what it is. It wouldn't matter how good Bash got as a shell language, this scenario wouldn't be any easier unless readline also gets a facelift.
- larrik 10y agoI actually did not know that.
- JeffreySnover 10y agoFor the record - the PowerShell team loves Bash and much of PowerShell is modelled after it. To be fair - we also modelled portions after VMS DCL, Perl, TCL and AS400 CL. There are lots of awesome engineers out there working on different platforms and we learned a lot from of them. Jeffrey Snover [MSFT]
- atmosx 10y agoYou can use Ctrl+R for reverse search. However, these are minor things... You can find a plugins and what-not to add these kind of functionalities. I use oh-my-zsh and I'm more accustomed with searching sub-history of commands, e.g. nmap <up> #=> shows flags...
- akerro 10y agoI do that same on bash and zsh since... ever?
- JeffreySnover 10y agoIt is just another tool in the toolchest. As you know, on Linux, there are tons of great interactive shells and it is sortof a lifestyle choice. You might want to kick the tires and see whether it fits your lifestyle or not. If you use Bash as your shell, think of PowerShell as you would python or perl - something you write scripts in and call from Bash. Jeffrey Snover [MSFT]
- denfromufa 10y agodoes powershell compile to IL? is it possible to create stand-alone executables from it that do not depend on the runtime?
- ygra 10y agoPowerShell is interpreted, as far as I know. Class declarations may be compiled on the fly, but I've never used them; I'm basically still at PowerShell v3/v4.
- JeffreySnover 10y agoWe have a hotspot compiler. We have talked about having it create a stand-alone executable but it has always fallen below the cut line. Jeffrey Snover [MSFT]
- xyzxyz998 10y agoThank you for doing this! Anyone who's done any kind of if else while for in bash/zsh and powershell knows what a relief PowerShell is. I'd love for PowerShell (PSReadline actually) to support the common options of readline- e.g. HISTIGNORE, HISTCONTROL etc
- satysin 10y agoIt is about Microsoft being a neutral player in a multiple platform world. Microsoft want people using their tools as it means they are more likely to use their platforms and services. Be it PowerShell on Linux or Bash on Windows or VSCode on macOS they want to make the best tools in the hope that it will push companies/developers towards Azure/SQL/Cloud as that is where the future for MS is. Windows is on life support and they know this. The future isn't about companies buying hundreds to thousands of Windows licenses but an instance of an OS which is billed per X/month. They have seen businesses are more than happy to enter into such a model with Office 365 and The Cloud so it makes sense for them to move in that direction.
- Grishnakh 10y ago>Windows is on life support and they know this. How is Windows "on life support"? Desktop/laptop computers are not going anywhere, at least until they invent some kind of VR (and no, mobile OSes like iOS are not suitable for doing real work and managing data in a networked environment the way desktop OSes are). Windows still has at least 90% of the OS market. People and businesses could change to an alternative, but they just aren't, and they aren't going to unless something really drastic happens to force them to (and this would likely have to include many popular applications also providing support for one or more of the alternatives). In the business/enterprise world at least, there is simply no indication that Windows is in any danger at all of losing marketshare or revenue, in fact it's probably going to increase since businesses seem to love the software-as-a-service model. MS could probably just make Windows free for home users (and make even money on them with advertising and selling telemetry data and also support calls), maybe small business users too, and then soak the big businesses with high fees for their site licenses and SaaS and other services.
- GVIrish 10y agoI would agree that Windows is nowhere near being on life support but I do think that the size of the desktop OS market is shrinking and that in the future we may see a lot more home computer users move to tablet only or something like a Chromebook. Enterprise users are much more slow to move but as enterprise SaaS offerings become more robust we may see a lot more businesses move towards a thin-client (a la ChromeOS) and SaaS model to meet their needs. Microsoft is doing the right thing by quickly getting out in front with Office 365. If they hadn't maybe something like Quip or Google Docs could have starting stealing significant market shared but now I don't think many enterprises would bother switching if they can stay with Microsoft.
- CodexArcanum 10y agoPowershell is really more about the scripting language and the command processing. The "shell" part is modular. On Windows you can still use most cmd tools inside powershell and with its commands. So you shouldn't give up bash, you should use both and take advantage of the tools that help you get the most done.
- adrianratnapala 10y agoI wonder the same, but I hope it succeeds. When PowerShell was written we knew more than when Bash, let alone the original Bourne Shell was designed. Powershell understands that parsing is sometimes hard. Powershell does not invite data-insertion attacks with the the fervour of Bash. In short, it does many things right that would Bash do too if it could be rewritten. And yet -- I've rarely found it useful in practice. But it's hard to judge that, since I don't do as much in Windows as I do on Unix. So this move will level the playing field a bit, and we shall have a fairer comparison.
- djsumdog 10y agoI think PowerShell would actually be way ahead of Bash. But we have things so much better than Bash. Python/Ruby let you do a lot of amazing stuff (not shells, I know, but still immensely more useful scripting languages than what you can do in Bash). Also, if you're still using Bash, I'd highly recommend looking at newer shells. Fish is pretty amazing. I've been using it over over a year. There are others too like Zsh.
- tombert 10y agoI actually use Zsh most of the time, but my point is that pretty much every Linux box has Bash at this point, so I'm a bit curious what Powershell has to offer.