Is there a *nix tool that can be piped into that forces a confirmation prompt before executing all previous commands? I'm thinking of a tool that would allow you to put commmand line snippets on a web page but guarantee that cut-and-pasting of the command and accidentally pasting a CR/LF wouldn't cause damage to the target's computer.

Here's a simple example assuming there's a tool called 'confirm' and replacing the dev with 'safedev':

head -c 32 /dev/urandom | sudo openssl enc -rc4 -nosalt -pass stdin -in /dev/zero -out /dev/safedev | confirm

This question stems from my own experience of wrecking my mbr by cut and pasting a command from a browser and it unexpectedly grabbing the CR/LF and begin executing before I had a chance to change sda to sdc. I was forced to recreate the mbr and reinstall Ubuntu Gnome over my existing partitions in order to recover/recreate my main OS.

If this tool doesn't exist, is there another way of providing commands on a webpage that can force confirmation before executing the commands? Maybe something like this?

confirm && head -c 32 /dev/urandom | sudo openssl enc -rc4 -nosalt -pass stdin -in /dev/zero -out /dev/safedev
  • Seems similar: unix.stackexchange.com/q/260395/117549 – Jeff Schaller Jan 6 '17 at 21:42
  • Even for the sake of a toy example, you shouldn't use openssl enc. People might get the impression that it can be used securely, whereas it pretty much can't. – Gilles Jan 6 '17 at 23:56
  • @Gilles+ and even though here you're only using enc as a cheapish PRNG, there is a 1/4 chance it produces less-random output than you expect and about a 1/16 chance it produces output that could be broken if you actually depended on its randomess, which in this case contrary to the tinfoil-hatters and checklisters you don't. – dave_thompson_085 Jan 7 '17 at 10:47

If you are pasting copied text into a terminal with embedded CRLFs, no prefixed command can save you (and indeed, tacking a command onto the end of a pipeline would be closing the door after all the cows have left the barn). Some terminal emulators (e. g. iTerm2 on OSX) have recently added CRLF detection and interception to mitigate this sort of problem.

Once you have solved the problem of embedder CRLFs, you can probably fake what you want with something like:

/bin/false && ( your commands here )

Once you have verified what you want is what you have, you can remove the /bin/false &&.

$ getraw --delay=1 'vent warp core? [yn]' && vent_warp_core

getraw (and the docs and the tests) could also be done with a read call in shell code, I guess.

This also should work in a pipeline, or within a while loop if there needs to be a per-file prompt. Totally contrived example:

find . -type f | ( getraw 'ready to cat?' && cat )
  • So far this looks the closest to what I'm looking for. – Dan Jan 7 '17 at 0:44

Similar to DopeGhoti's answer, but less rocket-sciencey: just type :

# ( your commands here )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.