mardi 7 septembre 2021

How do I count characters in bash using if statement?

Using an if statement in bash, I want count number of characters for files that are 1000 bytes. If the file is greater than 1000 bytes, then I want it to echo "Skipping Filename"

#!/bin/bash
FILES=$(/usr/bin/ls $@)
echo $FILES $@
for f in $FILES
do
   echo "Processing $f file..."    
if [ $FILES | wc -c) -gt 1000 ]
then
    echo "Skipping $"
elif [ $FILES | wc -c) -eq 1000 ]
then
# count number of characters and output that for file $f
    wc -c $f
fi

done

Is this how I'd go about it?

Aucun commentaire:

Enregistrer un commentaire