0

I know we can do things like this:

stat -f%z mybigfile > RELEASENOTES.txt

and

echo "bytes" >> RELEASENOTES.txt

Now RELEASENOTES.txt will look like this:

47556304
bytes

How can I get "bytes" on the same line? That is my goal, but if I only knew how to concatenate strings on the OS X Terminal command line then I could do that. Whichever answer is fine :-)

1 Answer 1

0

Current state:

BIGFILE=myverybigfile
echo File size: $(stat -f%z ${BIGFILE}) bytes > RELEASENOTES
echo ${whatissnewinthisbuild} >> RELEASENOTES

Got it! Something like this: (old)

BIGFILE="myverybigfile"
echo "File size:" `stat -f%z ${BIGFILE}` "bytes" > RELEASENOTES
echo "${whatissnewinthisbuild}" >> RELEASENOTES
3
  • 1
    Well done. I was just about to post the answer. Anyhow, $(stat -f%z ${BIGFILE} is recommended over the use of back-ticks. You also don't need the double quotes. May 13, 2015 at 23:10
  • 1
    You may be able to get away with leaving out the quotes in this case, because you’re dealing with relatively benign commands and you have a lot of control over the situation.  However, you should generally quote everything other than literal strings unless you have a good reason not to and you’re sure you know what you’re doing.  For example, try printf "foo %b bar\n" "\052"; then try echo File size: $(printf "foo %b bar\n" "\052") bytes.  … (Cont’d) May 14, 2015 at 7:22
  • 1
    (Cont’d) …  Also, saying ${BIGFILE} is not the same as quoting it.  If there’s any possibility that the filename contains special characters, you should say stat -f%z "$BIGFILE".  And, yes, it’s OK to have quotes within quotes in situations like this (echo "File size: $(stat -f%z "$BIGFILE") bytes"). May 14, 2015 at 7:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .