Reputation: 13
I'm trying to get all the regular files opened by all the processes in the current session. I have this code
while read pid
do
FILES_ACTUAL=$(lsof -p $pid | grep REG | wc -l)
done < <(ps -o pid,tt -u $USER | grep $CURRENT_TERMINAL | awk '{print $1}')
echo $FILES_ACTUAL
but I don't know how to add up, inside the while, the variable $FILES_ACTUAL.. I tried to use the awk command, but I couldn´t do it.
Upvotes: 0
Views: 129
Reputation: 565
There is also a comand called expr
which does simple arithmetic operations with integers and can be used like this:
expr $VAR1 + $VAR2
Upvotes: 0
Reputation: 1683
You can perform bash arithmetic by enclosing the statements inside (()):
NEW_FILES=$(lsof -p $pid | grep REG | wc -l)
((FILES_ACTUAL+=NEW_FILES))
Upvotes: 1