Glam Prestige Journal

Bright entertainment trends with youth appeal.

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

1 Answer

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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