Avatar of hankknight
hankknight
Flag for Canada asked on

Linux Shell: Pass number to command

In the code below, the number 99 is hardcoded.  How can I use $limit instead?
#!/bin/bash
limit=$((${1}+0))
if [ "$limit" -lt 1 ]; 
 then :
 limit=5
fi
echo `ps -eo "%c %C" | grep -v '%CPU' | grep -v '0.0' | sort | awk 'BEGIN{s="";}{if (s == $1){n=n+$2} else {if (s != ""){print s " " n};s=$1;n=$2}}END{if (s != ""){print s " " n;}}' | sort -rn -k +2 | awk 'BEGIN{p=0;} NR <= 99 {if(s==0&&$1!=""){s=1;print "\"hogs\":{"} if(s==1){if(NR != 1) { printf "," } printf " \"%s\":%.1f",$1,$2; }} END{if(s==1)print "}"}'`

Open in new window

Shell ScriptingLinux

Avatar of undefined
Last Comment
woolmilkporc

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
woolmilkporc

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck