Hi,
When new users start working on PowerShell the the main problem which they have faced is basic of PowerShell or we can say basic of any scripting language.
In this "PowerShell basics" tutorial series we are planning to cover as much as basics of PowerShell we can. These basics are not in any particular manner. The things which come in my mind and start covering them.
In the Part-1 we are covering "Single Quotes (') and Double Quotes ("").
In PowerShell we can use Single quotes and double quotes to access the folder and files which have space in there names. Without "single or Double quotes" PowerShell consider blank space as separator.
Have a Look.
Try to Get-Childitem of "Program files" with out space, and you will get an error that it not able to find "C:\Program". As i mentioned before that without quotes PowerShell treat "blank space " as separator.
Now lets wrap the the "Program Files" in Double or Single Quote. And this time it works Perfectly.
we can also use the single quotes to achieve the same. Let see another example.
I have a text file named as " Space test.txt", lets try to open it without quotes first.
OOps !! same error..
Wrap it Single or Double Quotes, this time lets wrap it in a Single quote and see what will happen. Working :)
But..the main difference in Single and Double quotes are described below.
"Double Quotes"
The Main Difference between "single and Double quotes" are that Variable are expands in "Double Quotes" but they don't expand in single quotes.
In variable $name i am assigning a value "Aman" let see if variable expand in $name.
You can see that in Write-Host "My Name is $name" , $name is changed with the value "Aman"
'Single Quotes'
The Single Quotes mainly used to mention the path to files and folders. I already mentioned the main difference above between "single and double" quotes that variables don't get expand in Single Quotes.
Let's look at same above example but with single quotes.
$name = "Aman"
You can see that in Write-Host "My Name is $name" , $name is not changed, that remain constant.
Thanks for Reading.
Aman Dhally
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.