How to take input from anything except [a-zA-Z0-9]
As i understand it there is no way of having <ENTER> or <SPACE> as an input (read value) - so how can I prompt a user for a file beginning with any option from [a-zA-Z0-9] and then give another option ideally of just pressing <enter> for all files and <esc> to exit?
couldn't track too much information on this, any help is greatly appreciated. |
I'm not sure I quite understand what you're asking. Reading input from what, into what? Using what? And your title doesn't seem to match your description. Care to give us a real example of what you want to do?
Are you talking about the shell read built-in? There's nothing special about enter or spaces there. All the enter button does is send a newline character into the buffer, and read by default terminates on newline. But you can set the -d option to terminate on some other character instead. |
Quote:
[Code] "Press Enter to list full directory of restores or just enter the first letter of filename:" read input if [ $input = [a-zA-Z0-9] ] find -L ./"$input" elif [ $input = [<ENTER KEY>] ls "/full directory of restores" Thanks in advance for help... |
I still don't understand completely.
What exactly should happen if the user enters a single letter? Your current code has it searching a directory of that name. (enter "a" --> list files in directory "a"). But you want it to match the start of a filename? If so, what file, and where? Could there be multiple matches, and what should happen if there are? Or do you just want it to just return a list of files to choose from; to create a sub-menu to make selecting the correct name easier? Please break down what you want to do in detail. Show us the directory and file structure, and give us a step-by-step run-through on what should happen at the command line. One possible simple solution may be to simply use the -e option in read to enable the readline library. This lets you use the shell's tab completion and other editing features to navigate your filesystem. As for testing the "enter key", the newline character it sends is the delimiter that terminates the read, so if there's no text the variable will be empty. So just test for nothing. |
All times are GMT -5. The time now is 10:34 PM. |