File size: Difference between revisions

→‎{{header|UNIX Shell}}: Attempt at a pure POSIX shell version
(add →‎Joy)
(→‎{{header|UNIX Shell}}: Attempt at a pure POSIX shell version)
Line 1,728:
size1=$(zstat +size input.txt)
size2=$(zstat +size /input.txt)</syntaxhighlight>
 
==Sh builtins only==
 
Tested on Alpine Busybox v1.35.0, passes shellcheck 0.8.0.
 
<syntaxhighlight lang="sh">
#!/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
</syntaxhighlight>
 
=={{header|Ursa}}==
89

edits