I am using while read do/ done to retrieve menu item.
Works as advertised, no problem.
I am using this hack function "pause" to stop script execution and wait for keyboard "enter" key to continue. Sort of break point function. Also works fine with one exception - it does not work when used within while do/done code.
No big issue, but like to know what so special with while do /cone code.
As far as I can tell I get no error or tracking info telling me why "pause" no longer waits for (any) key press. It just "passes thru " .
In this stripped down code I experience same problem when using "pause" in "inputBox" function
I am using while read do/ done to retrieve menu item.
Works as advertised, no problem.
I am using this hack function "pause" to stop script execution and wait for keyboard "enter" key to continue. Sort of break point function. Also works fine with one exception - it does not work when used within while do/done code.
No big issue, but like to know what so special with while do /cone code.
First off: while-loops are not special at all. AND you might want to investigate the select-keyword of the shell instead of rolling your own replacement for it.
One possible reason (to be honest there is too little information to accurately debug your problem) is that read reads from standard input. If you have redirected this input somewhere above in your script than it might read from some unexpected place.
Thanks, I think you answered my question.
The whiptail menu while read "searches" are indeed redirected and pause expect stdio.
It will take me a while to fix that after I'll take a harder look at "redirection".
------ Post updated at 08:56 PM ------
OK, I thought I can fix this myself, but I guess not.
Now for the stupid question - all info about redirection talks about redirecting FILES.
What is the correct syntax to redirect FUNCTION ?
I assume I will have to change the redirection after the pause returns the flow back to the "while do/done "
Here is the copy of pause , it just waits for "enter" key when working correctly
The read in the pause function competes with the read after while.
You can redirect the read to a keyboard device.
Or you can redirect the whole function
A good alternative is to use another descriptor for the while read
The descriptor 3 does not clash with the standard descriptors 0=stdin, 1=stdout, 2=stderr
Now for the stupid question - all info about redirection talks about redirecting FILES.
Short answer: because in UNIX everything is a file.
Long version: picture a process to be a garden hose. You pour water (data) into it at the top, inside something happens (the data is processed in some way), then the result comes out at the bottom.
Whatever comes out will land in a file called /dev/ttyX (or something similar, depending on your OS) which resembles the video hardware you are sitting at. Type something on your keyboard and some driver will move the typed characters into this file (from where some program - usually the shell - will pick them up), have the shell generate some output and it will land there, from where a driver picks it up and displays it on your screen. These two drivers basically constitute what is called a "terminal emulator".
To come back to the water hose picture: with redirection you can decide which device to attach to the various endings of the hose. Consider the command:
We usually say "it displays a directory listing", but in an absolute sense this is not the case: what it does is to generate a data stream with the directory information. We have a "hose" where nothing goes in and a stream of characters (the directory listing) comes out. Per default all the processes started from the shell are redirected to /dev/tty and this is why the generated data is displayed on your screen. But if we want it somewhere else we could re-redirect it somewhere else:
Now we have attached a "different bucket" to the ending of the water hose and the data lands now in it. The same way we could redirect the input to a process. Because ls does not want or need any input we use grep for that:
We have attached the file "/some/input" to the opening of the hose so the data in this file run into it. Inside "grep" does its work (it filters out lines containing "word", all others are dropped) and the result goes into another file attached to the bottom of the hose: "/some/output".
Now this is all fine but how about connecting a hose not to a bucket but another hose? We can do that too: this is called a "pipeline" and the symbol is "|". Let us have a look:
We have the first process ls which has no input but some output. This output is directly connected to the input of another process, grep, which further processes what ls emits. This now lands on the screen because of the default redirection i told you above, but we could further redirect this to another file or - by another pipeline - to another process.
It is even possible to create a filesystem representation of this pipeline: It looks like a file but in fact it is just a name where the output of one command is buffered until another command picks it up and processes it. This is called a "named pipe" and the command to create one is mkfifo.
Finally i want to confuse you hopelessly: the water hoses (processes) in UNIX are weird because they have, per default, not two openings, but three: stdin, stdout and stderr. Consider the hoses being Y-shaped, with two outlets, not one.
UNIX-processes use stdin for input. This is per default the keyboard as you can see when typing the command:
You will notice that this seems to "hang". In fact it does not hang but waits for input - your keystrokes. Type something and you will see that. Finally press CTRL-D, which creates the "END-OF-FILE"-character and all you have typed you will find in the file named "/some/file", which was what we redirected stdout to. Would we have not redirected it it would have landed on the screen - again, the default redirection.
This leaves stderr for explanation: this is where commands write their diagnostic messages to. It can be redirected the same way you can redirect stdout. Some are confused because these two are per default redirected both to the screen, so that both types of output land there. But if two different hoses deliver into the same bucket it doesn't mean they are identical! So let us try to separate them visibly:
Because "/etc/hosts" is a file that exists on practically every UNIX system and chances are "/bla/foo/bar" will not exist in yours you will get an output like this:
Notice that the first line has come via stderr, the second via stdout. No we will redirect away (to /dev/null, a file which devours everything sent to it - the trash can) the various parts:
We have redirected stdin so that will not land on screen any more.
Here we have redirected stderr. Notice that stdin, stdout and stderr are so-called "I/O-descriptors" and also numbered: 0 is stdin, 1 is stdout and 2 is stderr. This is why "2>" redirects stderr, the I/O-descriptor 2. We have left out 1 for our redirections up to now because it is the default but to be ultra-super-duper-correct we would write:
to redirect stdin.
I am already at the end, just one more thing: it would be nice to have the possibilty to redirect an I/O-descriptor to where another is already redirected. There is such a device:
The first rediction sends all stdin to "/some/file". The second redirects stderr to whereever stdin is already pointing at - in this case into the same file. Notice, though, that order matters! All these redirections are interpreted from left to right! So this:
Will not do the same as the command above, because first stderr will be redirected to where stdin points at - the screen - and only then stdin will be redirected to "/some/file", but this will not affect stderr at all.
Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK... (3 Replies)
I would like a script that would run pm-suspend if there has been no keyboard or mouse input for a specified time.
------ Post updated at 11:17 AM ------
Never mind. I found a setting in power management that does what I need. (0 Replies)
Hi all,
I'm installing a HP r2660 machine with HP-UX 11.23 (this version fixed by customer's product) and I've troubles using the VGA console as workstation display.
At first it worked just as TEXT console, then I fixed /etc/dt/config/Xservers and now I've the CDE prompt for login.
... (5 Replies)
Hi,
I need to provide more than one character to "> /dev/tty" through terminal/keyboard input, I have this:
ok=false
while
do
echo " Enter r1 to reformat "
> /dev/tty
read choice
case $choice in
)
echo " bla bla bla "
;;
done
However, in this way,... (3 Replies)
Sir
I have HP installed with SCO 6.0. The problems are (1) some keys in board like 'del' 'backspace', 'pageup/dn" do not function and display some special characters on conole. (2) Files transferred from Windows machine invariably contain control Z/M characters. How to resolve these issues.
... (4 Replies)
I am running Ubuntu 8.1 on a Toshiba Satellite P105-S9337 with built-in Bluetooth hardware. I cannot get the Bluetooth hardware to work with my Microsoft Bluetooth mouse.
I have installed the tosh software with no luck.
Does anyone have an idea as to what to try. I have several kernel mods... (0 Replies)
Hi All,
I'm getting this all the time with a regular user (after I do su - and smc):
It appears you are attempting to run the graphical
Solaris Management Console from a terminal which does
not have a suitable 'DISPLAY' environment. Please check
your 'DISPLAY' settings and that the user... (5 Replies)
Hello,
After seeing in a Unix cheatsheet that I could add commands into a file and run that file as a command to save on typing, i tried it with this:
#! /bin/csh
# Backup website excluding directories that do not change
rsync -e "ssh -p 2222" -axzvc --progress --stats --compress-level=9... (9 Replies)
I am new to unix, and this is my 1st post on this board. Looking for some advice about a cron job in my server.
I am running a cron task that references a script which runs several other scripts and compiles them into a report and emails it to me. If I run the script manually, I will... (2 Replies)
On the following script that I get an error when I try to execute as root:
#./mv_log.sh
bash: /root/util/mv_log.sh: Permission denied
#!/usr/bin
datetag=`date --date='1 day ago' +"%b%d%Y"`
logname=`find /opt/bea/wlserver6.1/config/*/logs/ -iname 'access.log0*' -mtime -1 -print`
mv... (4 Replies)