Re: simple shell script question

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

 



On 08/09/2017 05:47 PM, bruce wrote:
> trying to get the following to output
>   pgrep -f 'bash' | wc -l
> 
>   the var $xx has the cmd...
>   something's missing to allow the backtics to run the cmd..
>   if the cmd is hadcoded.run, it works..
> 
> can't see what the homer simpson "doh" moment is!

It's kind of silly to pass that through "wc". Just use the "-c"
option to pgrep:

[root@prophead ~]# ps ax | grep bash | grep -v grep | wc -l
28
[root@prophead ~]# pgrep -f bash | wc -l
28
[root@prophead ~]# pgrep -c -f bash
28

I think PHP actually tacks on a blank line when executing the stuff in a
backtick, so the "wc" value will always be 1 greater than the normal
return. That's just a guess from doing a var_dump() on the output of the
command:

	[root@prophead ~]# php -a
	Interactive shell

	php > var_dump(`pgrep -f bash | wc -l`);
	string(3) "29
	"
	php > exit
	[root@prophead ~]#

> #!/bin/bash
> #
> # ptest.sh
> #
> # use predefined variables to access passed arguments
> #
> # $1
> aa=$1
> aa='bash'
> echo $aa " pp"
> xx="pgrep -f '"${aa}"' | wc -l"
> echo $xx   <<< this dsplays the test pgrep
> echo `$xx`   <<  err msg
> echo `${xx}`  << err msg...
> 
> ## trying to get -- pgrep -f 'bash' | wc -l <<
> ## i'm getting a Usage: pgrep [....] err msg..
> _______________________________________________
> users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> 


-- 
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, AllDigital    ricks@xxxxxxxxxxxxxx -
- AIM/Skype: therps2        ICQ: 226437340           Yahoo: origrps2 -
-                                                                    -
-   To understand recursion, you must first understand recursion.    -
----------------------------------------------------------------------
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[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