2

I have the following:

echo "PLATFORM = $PLATFORM"
DATE_STRING=`date +"20%y-%m-%d"`
echo "DATE_STRING = $DATE_STRING"
# VERSION_LINE will be something like: '#define VERSION_STRING "1.2p2"'
VERSION_LINE=`grep "^#define VERSION_STRING" ../version.hpp`
#  - awk pulls the "1.2p2"
#  - tr deletes the surrounding quotes
VERSION_STRING=`echo "$VERSION_LINE" | awk '{ print $3 }' | tr -d '"'`
echo "VERSION_STRING = $VERSION_STRING"
echo "####### Creating Archive ###########"
BINARY_FILE="build${PLATFORM}-${VERSION_STRING}-${DATE_STRING}_CLXXXXXXXX.zip"
echo "BINARY_FILE is $BINARY_FILE"

The output is

PLATFORM = Linux64
DATE_STRING = 2015-10-31
VERSION_STRING = 1.2p2
####### Creating Archive ###########
-2015-10-31_CLXXXXXXXX.zip4-1.2p2

All the inputs to the expansion of BINARY_FILE look right to me, but the result is mucked up. I've run into this several years ago, but can never recall what causes it. Any ideas? Thanks!

  • i would guess it is a return character in your $VERSION_LINE pulled out of .hpp by grep. run ./yourscript | sed -n l – mikeserv Oct 31 '15 at 21:13
  • Wouldn't awk extract just my field? – Tim Oct 31 '15 at 21:22
  • 2
    dunno. is there a \return at the end of the line? is the field at the end of the line? even if im wrong about where it comes from or what it is, there is almost definitely something non-printable in there mucking about with the terminal display. run that command above to get a feel for what it is. by the way, it could very well be echo screwing with your output as well. a UNIX-standards-compliant echo will interpret C-style escapes in its arguments. – mikeserv Oct 31 '15 at 21:25
  • Yep. Right on. It was a \r somewhere the string. Can you post that as an answer so I can accept it? (Cut and past the above with "there is most likely ... ) – Tim Oct 31 '15 at 21:34
5

There is almost definitely something non-printable in there mucking about with the terminal display, and I have a hunch it is a \return character fetched out of ../version.hpp by grep into $VERSION_LINE and from thence by awk into $VERSION_STRING. I could be wrong, but you should run:

./yourscript | sed -n l

...to get a feel for whatever it is.

By the way, it could very well be echo screwing with your output as well. A UNIX-standards-compliant echo will interpret C-style escapes in its arguments.

  • 1
    piping to cat -v or cat -A is a good way of finding carriage-returns and other control-codes in output. – cas Oct 31 '15 at 22:52
  • @cas - possibly, but sed -n l is at least as good, and it is portable. – mikeserv Oct 31 '15 at 22:52
  • cat -A is GNU. cat -v and -t are portable. – cas Oct 31 '15 at 22:54
  • @cas - to linux and some bsds, yeah, probably. sed's l is POSIX. the only option POSIX spec's for cat is -u. another nice thing about it is the output format is also reliably specified. – mikeserv Oct 31 '15 at 22:55
  • @BinaryZebra - that doesn't give you a line-by-line view, exactly. also, without -v it squeezes consecutive sequences of input. and i dunno why you would do hex to find a \return or other non-printable: od -vtc <in. anyway, both sed and od are discussed in the linked answer. – mikeserv Nov 1 '15 at 0:27

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.