Search This Blog

Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts

Friday, April 5, 2013

Powershell tutorial for Linux users

Powershell vs bash Linux commands
Description Linux Bash Powershell
list all available commands Tab Tab gcm
multiple commands with a name foo type -a foo gcm foo
print PATH variable  echo $PATH  echo $env:path
print PATH variable  echo $PATH  echo $env:path
set or export a variable export VARIABLE="foo" $env:VARIABLE="foo"
bash navigation shortcuts - Tab
- history
- Control+U
-Control+K
-Alt+B/Control left
-Alt+F/Control right
- Control+R

- [Tab] Autocomplete folder/file name.
- F7 Show history of previous commands
- F9 Run a specific command from the command history.
- Ctrl Home Erase line to the left.
- Ctrl End  Erase line to the right.
- Ctrl arrow left Move one word to the left (backward)
- Ctrl arrow right Move one word to the right (forward)
- F8 Move backwards through the command history, but only display
commands matching the current text at the command prompt.

References
  1. http://technet.microsoft.com/en-us/library/hh849711.aspx
  2. http://ss64.com/nt/syntax-keyboard.html
  3. http://technet.microsoft.com/en-us/library/ff730964.aspx

Wednesday, April 3, 2013

Powershell as Bash substitute on Windows

In Linux we have Bash shell that can be used to interact with the system or help to execute routine commands. There are couple of other alternatives in Windows. The cmd.exe is one of the interpreters that comes with every Windows since years.

A new one I'm learning is powershell.exe. The good part about powershell is that it provides many commands like in Linux that have the same name buy maybe a slightly different syntax  For a nice comparison list between the standard bash and powershell commands please take a look at BASH and PowerShell Quick Reference.

Problem

What is the Linux Path variable in powershell.

Solution

The variable is called $env:path.
 
PS C:\Users\radoslaw> echo $env:path
%SystemRoot%\system32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\AMD APP\bi
n\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
 Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Git\cm
d;c:\Python27;c:\HP\DriveKey;C:\Program Files (x86)\PuTTY;C:\Ruby193\bin

You can modify it when navigating to:
Start - Computer - Properties - Advance system settings - Advanced-Environment Variables -System variables - Path
Problem

How to use 'curl' from powershell.

Solution

You can install cygwin on Windows. Add to the system PATH the cygwin bin directory. Alternatively you can use this command below to download a file.

 
PS C:\Users\radoslaw\tmp> (New-Object System.Net.WebClient).DownloadFile("http://python-distribute.org/distribute_setup.py", "tmp\distribute_setup.py")
PS C:\Users\radoslaw\tmp> ls

    Directory: C:\Users\radoslaw\tmp

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          4/3/2013   9:12 PM      17319 distribute_setup.py
-a---          4/3/2013   8:20 PM      85929 get-pip.py

References
  1. http://www.cs.wright.edu/~pmateti/Courses/233/Labs/Scripting/bashVsPowerShellTable.html