Sunday 17 January 2016

Bash shell script eval command

#!/bin/bash

#eval command - evaluate the expression and execute it
#provide input as username

if [ ! -z $1 ]
then
        proccomm="ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | grep $1"
else
        proccomm="ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu"
fi
eval $proccomm

No comments:

Post a Comment