0

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.

2 Answers 2

1

You can perform bash arithmetic by enclosing the statements inside (()):

NEW_FILES=$(lsof -p $pid | grep REG | wc -l)
((FILES_ACTUAL+=NEW_FILES))
Sign up to request clarification or add additional context in comments.

Comments

0

There is also a comand called expr which does simple arithmetic operations with integers and can be used like this:

expr $VAR1 + $VAR2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.