Subtract two variables in Bash

后端 未结 8 1944
时光取名叫无心
时光取名叫无心 2020-12-02 06:33

I have the script below to subtract the counts of files between two directories but the COUNT= expression does not work. What is the correct syntax?

<         


        
8条回答
  •  半阙折子戏
    2020-12-02 07:00

    White space is important, expr expects its operands and operators as separate arguments. You also have to capture the output. Like this:

    COUNT=$(expr $FIRSTV - $SECONDV)
    

    but it's more common to use the builtin arithmetic expansion:

    COUNT=$((FIRSTV - SECONDV))
    

提交回复
热议问题