1

How can I send a keystroke like 'q' to a script that ends with a call to less?

test.sh

ls -l | less

If I call test.sh it hangs and waits for the user type 'q'. How can I do something like this:

echo 'q' | test.sh

And have the script exit?

2
  • Did you try that exact thing? Did it work? Commented Mar 13, 2021 at 21:01
  • yes, it does not work.
    – Dranyar
    Commented Mar 13, 2021 at 21:02

1 Answer 1

1

You can do this, which still have less page the output, but it will exit when it hits eof.

LESS=-E ./test.sh

or

./test.sh | cat

which just dumps the output to the screen.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .