Simple Comparison: Bash versus PowerShell
This is just a simple glimpse into how I use Bash scripts and/or PowerShell scripts on my Windows 10 machine to automate my workflow and do more than one thing at a time.
I normally start my console emulator, cmder, as a Bash admin, but sometimes, I open a new tab as a PowerShell admin.
As you can see from the above image, I wrote the following scripts to quickly set me up for work:
- change my directory from the cmder to one of my destination work folders: my product reviews, local git repositories, and nodejs development folder.
- open the destination folder in Sublime
- open the destination folder in Windows Explorer
- show the path to the current (which was also the destination) folder
Here is the simple PowerShell script:
to run it on cmder, I just type:
gotoreview.ps1
Here is the simple Bash script:
to run it on cmder, I just type:
source gotoreview.sh
or
. gotoreview.sh
Notes: When running the Bash version of the program from cmder, always precede the filename with “source” or a “.” in order for change directory to work. Without it, the sublime command will run and windows explorer will open, but on you will not change directory to your TARGET folder. See the images below:
Incorrect:
Correct:
Further Learning
There are lots of websites that can help you learn either Bash or PowerShell scripting:
For PowerShell:
- Microsoft Documentation Page
- Another Microsoft PowerShell Documentation
- A PowerShell Primer article written by Jonathan Hassell for ComputerWorld.com
For Bash Scripting:
- Bash Beginners Guide by Machtelt Garrels
- Advanced Bash Scripting Guide by Mendel Cooper
- Udemy Courses
If you are interested in cmder, a powerful, portable console emulator for Windows, visit their site on cmder.net.