LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-01-2009, 11:03 AM   #1
dwj79
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
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!
 
Old 04-01-2009, 11:12 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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.
 
Old 04-01-2009, 11:14 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

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

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

vs

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

Hope this helps
 
Old 04-02-2009, 03:39 AM   #4
dwj79
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanx,

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

thanx again!
 
Old 04-02-2009, 03:46 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script command substitution and quoting brian4xp Linux - Software 8 02-05-2008 12:43 PM
Process Substitution not working with echo command muazfarooqaslam Linux - Newbie 1 02-04-2008 10:10 AM
Bash Command Substitution dakensta Programming 5 11-30-2006 04:10 PM
Command substitution and sed daYz Linux - General 9 11-04-2006 02:15 AM
command substitution: ^ rhxk Linux - General 2 04-06-2006 10:51 AM


All times are GMT -5. The time now is 11:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration