# Shortest code for a codegolf-style character counter without using bash [closed]

You have to write a program that will count all the characters in specified source file so that people entering a code golf competition can see their score. You do not need to ignore comments (it is code golf) in your program but newlines should be counted as a character. The number of characters must be printed to stdout. Shortest code wins!

Example in python:

import sys

try:
content = open(sys.argv[1], "r").read()
except IndexError, e:
print("No file specified")
sys.exit(1)
except IOError, e:
sys.exit(1)

count = 0
for i in list(content):
if(i!=''):
count+=1

print(str(count)+" characters long")


Note: you cannot use the bash command wc -c.

## closed as too broad by Doorknob♦, devnull, TheDoctor, Digital Trauma, user80551Mar 30 '14 at 7:35

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• 5 chars in bash. wc -c. This is trivial. – undergroundmonorail Mar 29 '14 at 21:45
• "Note: you cannot use the bash command wc -c." You can't fix a broken problem by banning one example of why it's so broken. – undergroundmonorail Mar 29 '14 at 21:50
• Question seems trivial. Also banning 'bash' while not banning the other '*sh' languages is essentially pointless. – Kaya Mar 29 '14 at 22:18
• In the future, you might want to run your questions by the sandbox to get help ironing out any problems. – undergroundmonorail Mar 29 '14 at 23:05

tr \\0-ÿ \\n|wc -l

Reads from STDIN. Doesn't use wc -c or Bash.
stat \$1