Subtracting an Integer from a Variable

Hello,

I am in following situation.-

COUNT=`ls -l | wc -l`
echo $COUNT
---> 26
NO_OF_FILES=$COUNT-1
echo $NO_OF_FILES
---> 26-1

Here, I want the output to be 25. How could I do this. It seems simple, but I am not getting it. Please help me.

use expr to do math.

NO_OF_FILES= expr $COUNT - 1

This should give you what you are looking for.

If you only want a file count, you don't need to subtract anything. Just issue:

COUNT=`ls | wc -l`

If you want to compute calculations and you're using bash, try:

x=10
x=$((x-1))
echo $x

Otherwise, go with "expr" as said by stcroix111 :slight_smile: