Presskey
Hello everyone,
This is "my first question", and I have to solve one problem with the bash scripts. My problem is: I am programming a bash file which will be used to create, delete and modify users and groups. Now I am building a menu, but I want to use the array keys to navigate in the system. My doubt is: How to press once a specifically key, and then, save that key in a variable, and continue the program. The next line don't run in my bash script: Code:
read -n1 "Press any key" var Thanks, Federico. |
Code:
read -a var -p "Enter a key: " -n 1 Then run your script with -x as outlined in my sig. jlinkels |
I write exactly this:
Code:
#!/bin/bash Code:
read: 3: Illegal option -a |
Code:
jlinkels@donald-pc:~$ cd /tmp Code:
jlinkels@donald-pc:/tmp$ bash -x readkey.sh Code:
jlinkels@donald-pc:/tmp$ bash --version Remove the shebang (#!/bin/bash) and run the command I did? jlinkels |
Lack of she-bang invokes /bin/sh which is platform-specific: ash/bash/dash/ksh/...
|
Quote:
Quote:
|
> Remove the shebang (#!/bin/bash) and run the command I did?
If you run the script with "bash <scriptfile>", then the she-bang won't hurt, because it is a comment. If you run the script simply entering "./scriptfile", then the lack of she-bang causes execve(2) to return ENOEXEC, which causes execlp(3) to invoke /bin/sh, which is platform-dependent. So I don't really see the point of removing the she-bang. |
I try to see the bash version: "GNU bash, version 3.2.49(1)-release (i586-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.". Now I solve the problem with this: Code:
read -rsn 1 var Now I've another problem, but I will post it in another post. Thanks again. |
All times are GMT -5. The time now is 05:47 PM. |