unix - Counting the number of files in a directory in bash -


i have bash script i'm trying find out number of files in directory , perform addition operation on well.

but while doing same i'm getting error follows:

admin> ./filecount.sh        1 ./filecount.sh: line 6: 22 + : syntax error: operand expected (error token " ") 

my script shown:

#!/usr/bin/bash  var1=22 var2= ls /stud_data/input_data/test3 | grep ".txt" | wc -l   var3= $(($var1 + $var2)) echo $var3 

can point out error.

can point out error.

  • you shouldn't have spaces around =.
  • you wanted use command substitution capture result in var2.

try:

var1=22 var2=$(ls /stud_data/input_data/test3 | grep ".txt" | wc -l)  var3=$(($var1 + $var2)) echo $var3 

moreover, say

var3=$((var1 + var2)) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -