LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-24-2011, 06:43 PM   #1
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
Old 10-24-2011, 07:51 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
Old 10-25-2011, 04:11 PM   #3
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by David the H. View Post
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.
Firstly apologies for not making my question clear, so I want my Bash shell script to ask the user to enter the first "Character" of a file name (in [a-zA-Z0-9]) to search ( find -L ./"$filename") or else press ENTER to list all files in my "Restore" directory. Is this possible as in;

[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...
 
Old 10-26-2011, 01:21 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HAL vs Xserver (/dev/input/mice?): convincing X to *not* use a given input device? stuartnlevy Linux - Desktop 6 01-24-2012 05:06 PM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 09:35 AM
HELP connecting MIC Input/Line Input with Jack and Qsynth animehair Linux - Software 0 07-28-2006 08:47 AM
Ctrl+Shift Unicode input gone, after installing Japanese Input Methodes polemon Linux - Newbie 1 09-20-2005 06:17 PM
Sendmail: timeout waiting for input from local during Draining Input andrewstr Linux - Software 0 07-14-2004 02:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration