Live data from Hacker News

$!134 can be a nice bash foot shooter if you accidentally mistype the number

news.ycombinator.com

1–10 of 54 posts

$!134 can be a nice bash foot shooter if you accidentally mistype the number

#1
I'm coding for a few years now, but today it was the first time I mistyped

$!

to repeat a command from the bash history. Fortunately it only launched a Python server. But finally you could accidentally hit any command from your past. It's like playing the lottery :-P

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#4
I don't use the terminal often, but when I do, the feeling of sheer power and control over the system is palpable. I'm a fast and nervous typer, so I always try to slow down and notice all the ways I could lose data, and how easy it would be to make such mistakes (eg. how many mistyped letters away from wiping my database am I?).

Over time, I got better at noticing danger areas. Whenever I use 'rm', I re-read the command a couple of times as an extra precaution. Doesn't feel like that's enough.

I wish we had --dry-run for everything.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#5
post #2

Fortunately my memory was never good enough for me to use that facility. C-r is how I always lookup earlier commands.

I always add

  "\e[A": history-search-backward
  "\e[B": history-search-forward
to my .inputrc, I find it easier to use than C-r as it's some sort of autocomplete from history. But looking up commands with !number can still be very useful when you don't remember the command you need but remember when you used it (e.g. what commands you ran before and after).

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#6
I never understood the utility of history substitution (I think this is what it's called). Why not just ctrl-r to see the actual command? Also, `sudo !!` thingy that is (was?) persistent in the internets for some reason, is probably the dumbest thing out there.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#7

I never understood the utility of history substitution (I think this is what it's called). Why not just ctrl-r to see the actual command? Also, `sudo !!` thingy that is (was?) persistent in the internets for some reason, is probably the dumbest thing out there.

“alias ffs=sudo !!” Is cute though.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#8

I never understood the utility of history substitution (I think this is what it's called). Why not just ctrl-r to see the actual command? Also, `sudo !!` thingy that is (was?) persistent in the internets for some reason, is probably the dumbest thing out there.

[deleted]

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#9

I don't use the terminal often, but when I do, the feeling of sheer power and control over the system is palpable. I'm a fast and nervous typer, so I always try to slow down and notice all the ways I could lose data, and how easy it would be to make such mistakes (eg. how many mistyped letters away from wiping my database am I?). Over time, I got better at noticing danger areas. Whenever I use 'rm', I re-read the com…

"echo" can be useful when prototyping scripts and for cycles, I prepend my critical commands (e.g. mv and rm) with echo and run the cycle to see all the commands with variables expanded before actually running them.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#10
You need to enable magic-space: https://relentlesscoding.com/posts/bash-magic-space/ # this will automatically expand any variables and history when you hit the spacebar after them, so you can eyeball before running.

Someone tell me what the zsh equivalent is?

Post reply on HN