RosettaCodeData/Task/File-size/UNIX-Shell/file-size-6.sh

18 lines
300 B
Bash

#!/bin/sh
unset PATH # No cheating!
countbytes(){
size=0
# Read the lines in the file
while read -r;do
size=$((size+${#REPLY}+1)) # +1 to account for the newline
done < "$1"
size=$((size+${#REPLY})) # Account for partial lines
echo "$size $1"
}
countbytes input.txt
countbytes /input.txt