Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining variables in a string

Status
Not open for further replies.

ngxGraz

Technical User
Jun 22, 2007
56
CA
Hi everyone, simple question here. I'm using powershell to automate some script calling, anyways in a function I want it to run a command

foocommand load C:\file\system\$prod_$sys\bla.out
and

foocommand load C:\file\system\$prod_32\bla.out

problem is, in these cases the shell look for a variable named $prod_ and one named $prod_32. How can I get the shell to recognize only $prod is the name? in perl I would just do
system("foocommand load C:\file\system\$prod"."_32\bla.out");

Thanks
 
& "foocommand load c:\file\system\" + $prod + "_32\bla.out"

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks, what's the point of the leading ampersand though?
 
oh, I should note the 'foocommand' is an executable found in my PATH, not a powershell function.
 
The leading ampersand tells the shell to execute the following string.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
The term 'foocmd load C:\file\sys\bla\obj\' is not recognized as a cmdlet, function, operable prog
ram, or script file. Verify the term and try again.

right after the OBJ is where I have the " + $product + "


so it looks like it's adding a CR somehow?
 
I figured it out.

no needs for quotes or ampersand

foocommand load c:\file\sys\obj\${prod}_$bla\file.obj

Thanks for the help though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top