This is for Linux Newbies when working with both Linux Ubuntu 16.04.01 and Windows Bash (which is based on Ubuntu 16.04.1). Please, get use the execute the following commands at least weekly as updates will be available frequently. And, specially before installing the next new release of PowerShell Open Source.
Look for PowerShell Open Source releases at: https://github.com/PowerShell/PowerShell
Follow these steps on a “Clean” Windows 10 Bash subsystem:
1. Run updates available:
$ sudo apt update
2. After the update there might be upgrade available, so list all upgradable components:
$ apt list --upgradable
3. If there’s a list of upgradable components then proceed with the upgrade step:
$ sudo apt upgrade
When installing PowerShell Open Source after a clean Windows Bash installation. Follow the Github instructions as the installation will end in errors. You must run the following command:
$ sudo apt-get install -f
But still, if it ends in error, try again the following commands on order:
$ sudo apt update $ sudo apt upgrade $ sudo apt install -f
You’ll notice the error will be cleared.
Also, be patience when e executing ‘sudo apt upgrade’ as this command will take a little time to complete.
One important thing, pay close attention the either Linux and Windows Bash messages when executing these commands as they will give valuable information. These messages will provide the hint on what to do in case of errors.
Running PowerShell Open Source
Now you can proceed to run powershell from Windows Bash. But it’s not there yet, you’ll still experience the screen issues when executing commands. This has been already noted in Github and they are still working on it.
So, the workaround still applies: http://www.maxtblog.com/2016/10/running-powershell-in-windows-10-bash-workaround/
For a quick console test, try using ‘screen‘ but need to run as ‘root’ privilege :
$ sudo screen
Here are some remediation to caveats with PowerShell when using ‘screen‘.
Important shortcut keys to remember:
1. Use CTRL-A & ESC – for PGUP/PGDN or ARROW UP/DOWN.
2. Use CRTL-L – to CLEAR the screen.
Also, caution, if you run any Linux command from PowerShell it will not terminate and you’ll need to close your session.
The workaround is the save the results of the Linux command to a PowerShell variable and the display the result.
For example, run in PowerShell prompt:
PS c:\Windows\system32> $x = dh -h; $x;
Now, if you run the linux command in PowerShell without saving to a variable, then you’ll get the session hung. To force PowerShell to get out of the hung state use CRTL-A and then CRTL-C. This will return to the Linux prompt(#).
Remember to exit ‘screen‘ by typing ‘exit‘ a few times until you get to the user ($) bash prompt.
So, with these few shortcuts, at least you should be able to work with PowerShell Open Source in Windows Bash console. I know its a little tedious but it will be rewarding at the end.
Just give it a shot, and keep learning PowerShell!