Hide Forgot
The ! command in bash retrieved the wrong history item. In my case it over wrote one of my files, but it wasn't too bad as I had it open in an editor. As you can imagine it could easily be disastrous results if it retrieved a more destructive command like "dd" or "rm -rf". Here's an exact copy and paste from my console : ------------------------ [1033:tedman@teds-t410:/data/repo/utils]cp target/oscar-utils-SNAPSHOT.jar ../oscar/utils/tasks/lib [1034:tedman@teds-t410:/data/repo/utils]mvn package && !cp mvn package && cp ../signature_pad/pom.xml . ------------------------ As you can see I run the "cp" command, the very next line I have a !cp, it should have retrieved the immediately prior line. Instead it retrieved a cp command from prior to that. My system info is as follows : Linux version 2.6.35.10-74.fc14.x86_64 (mockbuild.fedoraproject.org) (gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) ) #1 SMP Thu Dec 23 16:04:50 UTC 2010 GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu
Hmm, strange. It works for me. Is it reproducible for you? I can imagine only that your `cp' command you want is starting with some spaces. I know it is not shown here. You can watch your history and check if command you want really starts with `cp ' and not with any spaces (like ` cp').
it's not reproducible, although I haven't put much effort into trying. It's the first time I've seen such a thing. No there are no spaces in front of the cp command or anything weird. I've been refraining from using that option since then, I'll continue using it and if it comes up again I'll re-comment/re-open.
This just happened again, can we re-open this? here's my command line paste again : --------------------- [1015:tedman@teds-t410:/data/repo/oscar/src/main/java]find . > /tmp/j.txt && !grep find . > /tmp/j.txt && grep I3817 /tmp/l --------------------- So it thought !grep == "grep I3817..." Here's my history list --------------------- 1009 ls 1010 find . > /tmp/j.txt 1011 grep -v \*.java /tmp/j.txt > /tmp/j1.txt 1012 more /tmp/j1.txt 1013 grep -v \.java /tmp/j.txt > /tmp/j1.txt 1014 more /tmp/j1.txt 1015 find . > /tmp/j.txt && grep I3817 /tmp/l 1016 history --------------------- Notice the grep command isn't the previous one, nor even the prior grep, if I do a history | grep grep, I get --------------------- 942 grep I3817 /tmp/l 1011 grep -v \*.java /tmp/j.txt > /tmp/j1.txt 1013 grep -v \.java /tmp/j.txt > /tmp/j1.txt 1015 find . > /tmp/j.txt && grep I3817 /tmp/l --------------------- Notice it's a command from way back, not even the same day. I noticed in both cases I was doing a command && !history, maybe that has something to do with it?