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. |
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'.
|
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.
|
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......" |
Not sure whether "\n" is included as part of the returned read string. I thougt you could test on
Code:
if [ $var1 -eq "\n" ] Code:
if [ $var1 -eq "" ] It might be obvious, but run your program with Code:
sh -x myprogram.sh jlinkels |
All times are GMT -5. The time now is 05:55 AM. |