Macos – When I paste a command on the bash prompt it is not in history — how can I add it

bashgnome-terminalmacosterminal.appUbuntu

When I paste a command to my OS X or Ubuntu bash prompt using CmdV, the command is not in history – even if it is executed. The command is in history only if I type it.

How to enable that pasted commands get into bash's history?

Best Answer

There's an 'ignorespace' directive that won't save commands with blankspace at the start of the line, which is possible when you're cutting and pasting. There's an 'ignoredups' directive that only saves the earliest instance of a command, which might be the case here if you have a long history file and have used the command before. But, both of these are unset on my OSX10.6 machine, so unless you turned it on, these probably don't explain your situation.

Other scenario is that you've su-ed into another user, which could well be the case if you're cutting and pasting commands from somewhere else to get something fixed, so when you drop out of that user's (usually the root user's) context, the bash history is not available to you because it's in the privileged user's history, not yours.