[help] using $env

I

Irwin

i have a system variable named repo

an example of it is..
set repo = \\server

im trying to create a shortcut that links to that path, but i can't get the
syntax/format right.. here's what i've come out with so far. but it'll
probably read $env:tilltheend rather than $env:repo\blabla... if you know
what i mean.. how do i get this right?

$lnk.WorkingDirectory = "$env:repo\win7\netsetup\scripts"

if theres a better way do post so, thanks!!
 

My Computer

C

Chris Dent

Irwin wrote:

> i have a system variable named repo
>
> an example of it is..
> set repo = \\server
>
> im trying to create a shortcut that links to that path, but i can't get the
> syntax/format right.. here's what i've come out with so far. but it'll
> probably read $env:tilltheend rather than $env:repo\blabla... if you know
> what i mean.. how do i get this right?
>
> $lnk.WorkingDirectory = "$env:repo\win7\netsetup\scripts"
>
> if theres a better way do post so, thanks!!
>
It won't, it'll read and expand $env:repo, then concatenate that with
the rest. Run this to verify:

Write-Host "$env:repo\win7\netsetup\scripts"

Chris
 

My Computer

I

Irwin

What if I have

$abc = "Stu"
echo $abcpid
... nothing

right?
but yet..echo $abc\pid gives stu\pid

in linux, you can specify it like $(abc)pid.. and there are no problems here..

Anyway, I trialed an error for a bit and came up with $abc + "pid".. not
sure if this is a proper solution.

"Chris Dent" wrote:

>
>
> Irwin wrote:

> > i have a system variable named repo
> >
> > an example of it is..
> > set repo = \\server
> >
> > im trying to create a shortcut that links to that path, but i can't get the
> > syntax/format right.. here's what i've come out with so far. but it'll
> > probably read $env:tilltheend rather than $env:repo\blabla... if you know
> > what i mean.. how do i get this right?
> >
> > $lnk.WorkingDirectory = "$env:repo\win7\netsetup\scripts"
> >
> > if theres a better way do post so, thanks!!
> >
> It won't, it'll read and expand $env:repo, then concatenate that with
> the rest. Run this to verify:
>
> Write-Host "$env:repo\win7\netsetup\scripts"
>
> Chris
> .
>
 

My Computer

C

Chris Dent

In that case PS is expecting you to have a variable named $abcpid, not
$abc concatentated with pid.

Sub-Expressions this time:

"$($abc)pid"

It has to be clearly presented to PS, if the characters after the
variable can be part of a variable name then it will fail.

For example:

$abc = "123"
Write-Host "$abcpid"
Write-Host "$abc"
Write-Host "$($abc)pid"
Write-Host "$abc:Something" # Remember the use of
$Env:SomeVariable, no such thing here
Write-Host "$($abc):Something"

And so on.

> not sure if this is a proper solution
It's a valid one, nothing wrong with it although not all that many
examples use it, in part because it means more typing, and more opening
and closing of string blocks :)

HTH

Chris

Irwin wrote:

> What if I have
>
> $abc = "Stu"
> echo $abcpid
> .. nothing
>
> right?
> but yet..echo $abc\pid gives stu\pid
>
> in linux, you can specify it like $(abc)pid.. and there are no problems here..
>
> Anyway, I trialed an error for a bit and came up with $abc + "pid".. not
> sure if this is a proper solution.
>
> "Chris Dent" wrote:
>
>

>> Irwin wrote:
>>

>>> i have a system variable named repo
>>>
>>> an example of it is..
>>> set repo = \\server
>>>
>>> im trying to create a shortcut that links to that path, but i can't get the
>>> syntax/format right.. here's what i've come out with so far. but it'll
>>> probably read $env:tilltheend rather than $env:repo\blabla... if you know
>>> what i mean.. how do i get this right?
>>>
>>> $lnk.WorkingDirectory = "$env:repo\win7\netsetup\scripts"
>>>
>>> if theres a better way do post so, thanks!!
>>>
>>>
>> It won't, it'll read and expand $env:repo, then concatenate that with
>> the rest. Run this to verify:
>>
>> Write-Host "$env:repo\win7\netsetup\scripts"
>>
>> Chris
>> .
>>
>>
 

My Computer

Top