LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   passing a veriable in a command substitution (https://www.linuxquestions.org/questions/programming-9/passing-a-veriable-in-a-command-substitution-716071/)

dwj79 04-01-2009 10:03 AM

passing a veriable in a command substitution
 
Hi,

im trying to do the following:

Code:

MYVAR="filename.php"
CMSUSER= $(stat --format=%U $MYVAR)

Anyway the command substitution statent doesn't seem to recognize the variable.
how can i make it work?

thanx in advance!

acid_kewpie 04-01-2009 10:12 AM

the substituion works fine, but you have a space after CMSUSER= which means you're making that value null, and then looking to execute the output of the stat command and another command in itself, also not making sense. just remove the space.

druuna 04-01-2009 10:14 AM

Hi,

There's a space between = and $(...... Remove the space:

CMSUSER= $(stat --format=%U $MYVAR)

vs

CMSUSER=$(stat --format=%U $MYVAR)

Hope this helps

dwj79 04-02-2009 02:39 AM

Thanx,

im kinda newbie to bash :P and sometimes it's difficult to deal with such a strict syntax :D

thanx again!

acid_kewpie 04-02-2009 02:46 AM

It might seem strict, but it's not really, it's just illogical. As bash is a shell and not a programming language, each line is a command in it's own right, not a line of code. So whitespace has to matter in certain contexts in a way that a single line of java needn't, as you're actually splitting one operation into two different things with the whitespace.


All times are GMT -5. The time now is 11:05 AM.