11

I would like to have the following command structure:

command && check-status | less && followup-command

This would pause the execution while the user interacted with less. How can the user force less to exit with a non-zero status to prevent followup-command from running?

I am currently using less 458 (POSIX regular expressions)

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
user2943160
  • 537
  • 2
  • 5
  • 10

1 Answers1

15

In the simple case, you can ask less not to handle SIGINT, then Control-C will kill it and the exit code will be non-zero. Do this with option -K.

command && check-status | less -K && followup-command

As a workaround for older versions of less, you can do something like

command && bash -c 'trap "exit 1" int;check-status | less -K;' && followup-command

If you don't have -K, omit it, but you'll have to signal and then type quit too.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
meuh
  • 49,672
  • 2
  • 52
  • 114