LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-22-2007, 04:28 PM   #1
Gremlin2
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Rep: Reputation: 0
Display current value


Hi all,

How can I display a current variable value while performing read?
In other words, in case of standard echo/read sequence – something will be displayed first and then my script will stop, waiting for user input. But nothing will be displayed as a “default value” for that “read” (i.e. something already written as an input for read while the user is able to edit it and eventually, after the “enter” was hit – the finial text will be read by the “read” command).

IMHO, any professional level script should suggest a user with a default value for something, allowing the user to simply hit “enter” and accept the proposed value while sill allowing users change it to some other (desired) value. How can I do it in BASH Scripting?

Any answer will be appreciated,
Alex.
 
Old 10-22-2007, 05:00 PM   #2
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
I don't quite understand your question. But 'read' by definition waits for input. If you want to read something that might be there or not before actual access attempt, you might consider creating a fifo. More on creating and using fifo's are on the Web, and 'man mkfifo'.
 
Old 10-22-2007, 05:22 PM   #3
Gremlin2
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Look, indeed the read command waits for user input. But the question is how can I suggest something as such input, primary by placing it on behalf of user input (i.e. defaut value)? Usually, the read command allows you to enter your input and then hit "enter" but if there is something already typed in and the user can simply hit "enter" (accept it) and continue or he can delete it and type in something else? Such a suggested answer for read, that's what I'm interested in.
 
Old 10-22-2007, 07:05 PM   #4
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
I see... . But then you could use 'read', but before you do:
Code:
@echo "If your want default value of 10 hit Enter, otherwise type your value......"
read var1
if [ $var1 -eq $NEWLINE ] then;
((var1=10))
fi
You should figure out how to see if var1 is a newline, I can't tell from the top of my head.
 
Old 10-22-2007, 08:21 PM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,981

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Not sure whether "\n" is included as part of the returned read string. I thougt you could test on
Code:
if [ $var1 -eq "\n" ]
or
Code:
if [ $var1 -eq "" ]
One of the two will work, and echoing any read in variable in Bash is a must during development anyway.

It might be obvious, but run your program with
Code:
sh -x myprogram.sh
You'll see what is going on.

jlinkels
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display current IP address ust Linux - Software 2 07-25-2007 01:08 PM
how to display the current time at a different timezone stinkytofoo Linux - Software 3 07-18-2007 03:41 AM
Display current refresh rate (XFree) McCloud Debian 2 11-11-2004 05:34 AM
Display the current forum's questions in frame vharishankar LQ Suggestions & Feedback 6 09-10-2004 11:37 AM
command to show current display resolution ?? itsjustme Slackware 4 12-05-2003 01:59 PM


All times are GMT -5. The time now is 10:50 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration