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 :-)

Jonny
  • 545
  • 2
  • 9
  • 23

1 Answers1

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
Jonny
  • 545
  • 2
  • 9
  • 23
  • 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. – Anthony Geoghegan May 13 '15 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) – G-Man Says 'Reinstate Monica' May 14 '15 at 07:22
  • 1
    (Cont’d) …  Also, saying `${BIGFILE}` [is not the same as quoting it](http://unix.stackexchange.com/questions/4899/var-vs-var-and-to-quote-or-not-to-quote).  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](http://superuser.com/a/909811/354511) in situations like this (`echo "File size: $(stat -f%z "$BIGFILE") bytes"`). – G-Man Says 'Reinstate Monica' May 14 '15 at 07:24