shell script : if array value was greater than a number then run a command -
i have a files containing usernames , users sent count mail per line . example (dont know how many line have ) :
info.txt >
500 example1 40 example2 20 example3 .... .. .
if number greater x , want run commands containing user name , act on user .
getarray() { users=() # create array while ifs= read -r line # read line users+=("$line") # append line array done < "$1" } getarray "/root/.myscripts/spam1/info.txt" # know part incorrect , need here : if [ "${users[1$]}" -gt "50" ] echo "${users[2$] has sent ${users[1$]} emails" fi
please help
thanks
not knowing how many lines of input have no reason use array. indeed, more useful if assume input infinite (an input stream), reading array impossible. read each line , take action if necessary:
#!/bin/sh while read -r count user; if test "$count" -gt 50; echo "$user has sent $count emails" fi done < /root/.myscripts/spam1/info.txt
Comments
Post a Comment