coanda
asked on
Passing bash array to perl
I have a shell script that checks how many instances of an application that are open and I would like to check the length of it to decide what to do next, currently I'm doing:
LIST=`pidof urxvt`
CNT=`perl -e '@ret=qw($LIST); print scalar @ret;'`
if [ "$CNT" -le 2 ]; then
...
fi
The problem is that the $CNT always = 1, it's pretty obvious that I'm not using the correct syntax to pass $LIST into the line of perl but I can't seem to find how to do it correctly. There's likely other ways of doing this than using perl but I'm more interested in how to do using perl than I am by using awk, python, or any of the numerous other options.
Thanks in advance.
LIST=`pidof urxvt`
CNT=`perl -e '@ret=qw($LIST); print scalar @ret;'`
if [ "$CNT" -le 2 ]; then
...
fi
The problem is that the $CNT always = 1, it's pretty obvious that I'm not using the correct syntax to pass $LIST into the line of perl but I can't seem to find how to do it correctly. There's likely other ways of doing this than using perl but I'm more interested in how to do using perl than I am by using awk, python, or any of the numerous other options.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In fact, you can simplify it further
if [ $(pgrep -c urxvt) -le 2 ]
then
...
fi
Open in new window