key=$(enterchr "Are you sure?: ")
if [ "$key" = "Y" ]; then
echo "You entered Y"
else
echo "You entered N"
fi
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#ifdef __USE_GNU_GETTEXT
#include <libintl.h>
#define _(String) gettext(String)
#define gettext_noop(String) String
#define N_(String) gettext_noop(String)
#else
#define _(String) (String)
#define N_(String) String
#define textdomain(Domain)
#define bindtextdomain(Package, Directory)
#endif
int main(
int argc,
char **argv) {
char c = 'Y';
char *msg;
struct termios raw_tioctl;
char emsg[128];
if (argc < 2)
strcpy(emsg,
_(
"Press any key"));
else
strcpy(emsg, argv[1]);
tcflush(0, TCOFLUSH);
while (1) {
msg = emsg;
while (*msg) {
write(2, msg++, 1);
}
if (read(0, &c, 1) > 0) {
write(1, &c, 1);
break;
}
}
if (c == (char)0x1b)
return (1);
return (0);
}
Headder for C-Menu API library, libcm.so.
struct termios shell_tioctl
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
bool mk_raw_tioctl(struct termios *)
mk_raw_tioctl() - set terminal to raw mode
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings