A concept problem
i have concept @(...) , $(...)
if have 2 script codes.
one @("bbb","aaa","ccc" | sort)[0]
the other $("bbb","aaa","ccc" | sort)[0]
the above outcome aaa
however if change below
one @("aaa" | sort)[0]
the other $("aaa" | sort)[0]
the outcome different.
i not understand different @(...) , $(...). kindly explain me?
thanks,
if have 2 script codes.
one @("bbb","aaa","ccc" | sort)[0]
the other $("bbb","aaa","ccc" | sort)[0]
the above outcome aaa
however if change below
one @("aaa" | sort)[0]
the other $("aaa" | sort)[0]
the outcome different.
i not understand different @(...) , $(...). kindly explain me?
thanks,
@() array notation, forces result an array.
$() sub-expression notation. you can write multiple commands (expressions) inside. result can 1 object or more.
1. @("bbb","aaa","ccc" | sort)[0]
2. $("bbb","aaa","ccc" | sort)[0]
in case of 2 commands above, both returns collection of objects , ask first item in index 0 (e.g. 'aaa').
when change commands to:
1. @("aaa" | sort)[0]
2. $("aaa" | sort)[0]
there nothing sort cause there's 1 object (scalar), when ask powershell return first item gives first char in string, if did:
ps > "aaa"[0]
a
shay levy [mvp]
http://blogs.microsoft.co.il/blogs/scriptfanatic
powershell toolbar
$() sub-expression notation. you can write multiple commands (expressions) inside. result can 1 object or more.
1. @("bbb","aaa","ccc" | sort)[0]
2. $("bbb","aaa","ccc" | sort)[0]
in case of 2 commands above, both returns collection of objects , ask first item in index 0 (e.g. 'aaa').
when change commands to:
1. @("aaa" | sort)[0]
2. $("aaa" | sort)[0]
there nothing sort cause there's 1 object (scalar), when ask powershell return first item gives first char in string, if did:
ps > "aaa"[0]
a
shay levy [mvp]
http://blogs.microsoft.co.il/blogs/scriptfanatic
powershell toolbar
Windows Server > Windows PowerShell
Comments
Post a Comment