LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell command for pausing (https://www.linuxquestions.org/questions/linux-newbie-8/shell-command-for-pausing-184798/)

Toshi3 05-23-2004 09:13 AM

shell command for pausing
 
Hi,

Is there a shell command that will "sleep" until a key is pressed (similar to getch() in C)?

Thanks,

Toshi

david_ross 05-23-2004 10:40 AM

You can use:
read -n1

Or slightly better:
read -sn1 -p "Press any key to continue..."

Toshi3 05-23-2004 11:04 AM

Thanks,

read works fine in bash, but what about csh and tcsh ?

I would appreciate any help,

Toshi

david_ross 05-23-2004 01:17 PM

I don't tend to write anything in shells other than bash but you could always start bash to run it:
bash -c "read -sn1"

If you want something that will work in all shells then you'll need an additional program such as pak.c:
Code:

#include <stdio.h>

int main(void)
{
 printf("Press any key to continue...");
 while (getchar() == EOF);
 printf("\n");
 return 0;
}

gcc -o pak pak.c

Toshi3 05-23-2004 03:10 PM

Thanks a lot!

bash -c "read -sn1" is perfect.

Toshi


All times are GMT -5. The time now is 12:03 AM.