If I type the % character in the Terminal, it breaks that shell and every new shell I open until reboot:

$ seq 10 | parallel -j50% "echo Hi {}"
-bash: printf: `"': invalid format character

Does anybody know why this is?

To expand a bit more, if I open a Terminal, and echo "100%", this happens:

Last login: Fri Nov 21 08:28:47 on ttys033
~$ echo "100%"
-bash: printf: `"': invalid format character

0; echo "100~$ 
-bash: printf: `"': invalid format character
-bash: printf: `"': invalid format character
-bash: printf: `"': invalid format character

Every time I press RET after putting a percent character in, the Terminal flashes and prints an error statement about printf. I was actually working on this more after I posted the question and one thing I did was upgrade bash:

~$ echo $BASH_VERSION 

This helps. Previously it was Bash 2.something (if I recall - whatever Mountain Lion's default is). In that version of Bash, every open Terminal window aside from the one where I put the % was okay, but every new one I opened was also corrupted and nothing could get the Terminal back but rebooting.

Now, with Bash 4.3, I can type a command to get the prompt back to normal. And new Terminal windows are also okay.

But - I still can't use % in commands I put into the Terminal. Fortunately, I don't need to often, but things like awk just don't work for me on my Mac.

So, my $PS1 is:

~$ echo $PS1
\[\e[0;34m\]\W\[\e[0;31m\]$ \[\e[0m\]

If that looks confusing at first, these are colors I am setting in my bash_profile:

# colours for use in prompts
export PS1="${BLUE}\W${RED}\$ ${NOCOLOR}"

If I echo "100%" with another user account, it is okay! So clearly, I am shooting myself in the foot somewhere in my .bash_profile. Which is too bad, because I basically like my setup, or so I think, ha!

If anybody wants to look at my dot files they're now on GitHub. (I am a bit embarrassed to show them - there is some cruft there, haha.)

  • You mean if you type it in that command? What does "break" mean?
    – miken32
    Commented Nov 20, 2014 at 21:44
  • Hi, if I type a % character in just about any command, the Terminal goes haywire. The example above was just the most recent one, so that is what I copied and pasted in. But also hits me when using awk as well. Commented Nov 20, 2014 at 22:01
  • It might help to edit and provide some more details in your question. Again, what exactly happens? "Breaks" and "goes haywire" aren't going to help. A screenshot of your terminal might help, after typing a very simple command like echo "100%"
    – miken32
    Commented Nov 20, 2014 at 22:04
  • Okay, I edited and made some additional comments... Commented Nov 21, 2014 at 15:08
  • What does echo $PS1 give you?
    – miken32
    Commented Nov 21, 2014 at 15:42

2 Answers 2


Looking at your .bash_profile, this seems to be the most suspicious line:

trap 'printf "${OPENTITLEBAR} `history 1 | cut -b8-` - `pwd` ${CLOSETITLEBAR}"' DEBUG

It is doing a printf on the history (which will contain your % character).

I have no idea what that is intended to do (update window title with last command?), but I would guess if you comment it out, the error will stop.

  • Yep, that was it. I had that set so it would echo my last command to the title bar across the top of the Terminal window, which was cool, but not worth functionality. Thanks to all who commented! I wish I had enough rep to up vote everyone appropriately. Commented Nov 22, 2014 at 23:20

Analyzing these kind of problems is always tricky. I usually create a new account without any bash configuration to start from a clean slate (assuming the problem doesn't show up there) and then work upwards from there by adding config file by config file (or line by line if necessary).

Besides the usual suspects (.bash_profile, .profile, or .bashrc) you may also want to look at .inputrc, /etc/profile and any file sourced from one of these.

  • You're right - testing a blank account showed no problems. I'm suspicious of one particular line in my bash profile right now thanks to yours and miken's comments (the only line with printf), but am not in a good position to test it just now... Commented Nov 22, 2014 at 12:13

You must log in to answer this question.

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