0

say I have a file called file1

$ a=$(wc -c file1)
$ echo $a
233 file1

now how would I do this

$ b=$(expr $a % 2)
$ echo $b
1

I guess the file1 in wc -c make's this crash?

1

Another way to remove the filename from wc is to use wc -c <file1. This avoids the requirement of a second process cat.

2

I would use something like:

if [ $(( $(wc -c < your-filehere ) % 2)) -eq 1 ]
then 
  echo file has odd number of bytes
else 
  echo file has even number of bytes
fi
0

One way to go:

a=$(cat file1 | wc -c)

this doesn't output the file name and your expr will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.