Skip to content

Instantly share code, notes, and snippets.

@drench
Created August 13, 2011 05:32
Show Gist options
  • Select an option

  • Save drench/1143509 to your computer and use it in GitHub Desktop.

Select an option

Save drench/1143509 to your computer and use it in GitHub Desktop.
necho(): attempt echoing without a newline, under any common shell
necho() {
echo -n "$*"
}
if [ -s "$BASH" ]; then
e=`necho A; echo B`
if [ "$e" != "AB" ]; then
shopt -s xpg_echo
necho() {
echo "$*\c"
}
fi
fi
@drench
Copy link
Author

drench commented Aug 13, 2011

Built-in echo under OS X 10.6.8's /bin/sh doesn't honor "-n". /bin/sh is bash, though it's not the same as /bin/bash (the file sizes and contents are slightly different). There's some discussion about this at https://discussions.apple.com/thread/3177477 but no solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment