Re: OT: need bash help [solved]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17 October 2011 20:45, Mike Wright <mike.wright@xxxxxxxxxxxxxx> wrote:
> On 10/17/2011 12:39 PM, Mike Wright wrote:
>> Hi all,
>>
>> I'm trying to write a bash script and having problems.
>>
>> If I execute this:
>>
>>     ps x | grep mongod | wc -l
>>
>> it returns a value.
>>
>> OTOH, if I execute this:
>>
>>     LINES = ps x | grep mongod | wc -l
>>
>> it returns "command not found".
>>
>> How does one assign the output of a command to an environment variable?
>
> Aaargh!  Doesn't like the spaces around the = sign.
>
> LINES=`ps x | grep mongod | wc -l` is a way to write it.
>

There's quite a good explanation of that somewhere, I think in the
bash manual. It boils down to:
X=A
is an assignment (to X)
X =A
is a command (run X, argument, '=A')
X= A
is an assignment (X="") followed by a command (A) run with that
assignment in effect (normally you need to export the value for it to
affect the child process).

Exercise left for the reader as to what
X = A
is.
-- 
imalone
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux