Re:An UPDATE without a WHERE, or something close to it
by mprovost on Friday October 29, 2021 @09:45AM
(#29038314)
One quick trick I use a lot in the shell is to run a known safe command with the argument first, and then run the dangerous command with the the !$ variable (the last argument of the previous command) so there's no possibility of a mistake in copying and pasting. Something like: `ls /tmp/junk; rm !$`.
[ Parent
| on HN ]
Re:An UPDATE without a WHERE, or something close to it
by benjaminwai on Friday October 29, 2021 @11:11AM
(#29039412)
I think !$ takes the last argument on the previous command in history, not previous one on the same line.. at least in bash. For example, if you do:
$ ls /
$ ls /tmp/junk; rm !$
It's taking "/" rather than "/tmp/junk"..EDIT: formatting
Re:An UPDATE without a WHERE, or something close to it
by mprovost on Friday October 29, 2021 @12:33PM
(#29040494)
Yes that's right it's the previous command from history. That way you run ls and see if it's the expected output, then rm to delete.
Re:An UPDATE without a WHERE, or something close to it
by BossingAround on Friday October 29, 2021 @03:24PM
(#29042540)
Point being that "ls /path; rm $!" deletes something entirely different than "/path".
What you want is "ls /path; rm $_".
Even then, the above is fairly pointless. At the time you look at what you are deleting, it's gone.
Re:An UPDATE without a WHERE, or something close to it
by witrak on Friday October 29, 2021 @03:42PM
(#29042715)
I think you misunderstood the previous comment. I think that firstly "ls /path" is entered and if the result is ok, then "; rm $_" is added to the copy of the command then executed.
Re:An UPDATE without a WHERE, or something close to it
by BossingAround on Saturday October 30, 2021 @02:36AM
(#29046549)
Yes, at which point you simply do:
1. ls /path
2. rm <esc><.>
(where "escape" "dot" brings up last argument) without the need to fiddle around with dollar signs underscores, exclamation marks, etc. to prevent further mistakes (e.g. "was it $! or !$ ?", shell expansion, etc)