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?
TIA,
Mike Wright
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
10-17-2011, 07:43 PM
Larry Brower
OT: need bash help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On 10/17/2011 02: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?
>
> TIA,
> Mike Wright
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.
Sorry for the noise :/
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
10-17-2011, 07:46 PM
Emmett Culley
OT: need bash help
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?
>
> TIA,
> Mike Wright
You can use:
LINES=`ps x | grep mongod | wc -l`
(using back ticks to bracket the command)
Emmett
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
10-17-2011, 07:54 PM
Pete Travis
OT: need bash help
Try wrapping your command to make a subshell:
LINES=$(ps x| grep mongod | wc -l)
HTH,
Pete
On Oct 17, 2011 1:39 PM, "Mike Wright" <mike.wright@mailinator.com> 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?
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
10-17-2011, 08:06 PM
Pete Travis
OT: need bash help
Backticks for a subshell are 'depricated' though the convention is still in wide use.* I use the $() method because `su - user 'command --opt="foo"'` and such can get a bit confusing,* and the alternative is much easier to pick out of a mass of text.
On Oct 17, 2011 1:45 PM, "Mike Wright" <mike.wright@mailinator.com> 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.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
10-17-2011, 10:33 PM
Ian Malone
OT: need bash help
On 17 October 2011 20:45, Mike Wright <mike.wright@mailinator.com> 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@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
10-18-2011, 12:10 AM
g
OT: need bash help
On 10/17/2011 07:39 PM, Mike Wright wrote:
> Hi all,
>
> I'm trying to write a bash script and having problems.
you seem to have several replies that can give you what you want.
here are a couple links that i have found helpful;
*please reply "plain text". "html text" are deleted*
****
in a free world without fences, who needs gates.
**
help microsoft stamp out piracy - give linux to a friend today.
**
to mess up a linux box, you need to work at it.
to mess up an ms windows box, you just need to *look* at it.
**
The installation instructions stated to install Windows 2000 or better.
So I installed Linux.
**
learn linux:
'Rute User's Tutorial and Exposition' http://rute.2038bug.com/index.html
'The Linux Documentation Project' http://www.tldp.org/
'LDP HOWTO-index' http://www.tldp.org/HOWTO/HOWTO-INDEX/index.html
'HowtoForge' http://howtoforge.com/
****
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines