ash busybox read command not working inside function....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ash busybox read command not working inside function....
# 1  
Old 08-23-2012
ash busybox read command not working inside function....

I have a script that has to execute a read command in a function, this is in an ash busybox.

The code is...

Code:
trapcatch ()  { echo "Ctl-c Detected, what do you want to do?"   
echo "Please choose the number of one of the following options"   
echo "1.  Jump past this Set"   
echo "2.  Exit altogether"   
echo "Any other key or no key just continues"    

read -t 5 -p "Choose option 1-3 now : " KEYHIT    

case $KEYHIT in   

1*) echo "OK, I'll bypass this Set then"       
continue 2       
;;   

2*) echo "OK, I'll exit gracefully then"       
# need to add the graceful exit here       
exit 99       
;;   

*)  echo "OK I'll just carry on then......"       
;;   

esac    }

However the prompt in the read command is never appearing and indeed the script is just falling through to the 'OK I'll just carry on then...." option in case.

So it looks to me like the read command is not getting executed at all, however if I put the same read line in a separate stand alone busybox script it seems to work.

Could someone possibly explain why.

Last edited by tesser; 08-23-2012 at 12:19 PM.. Reason: layout
# 2  
Old 08-23-2012
ash does not support the read -t BASH extension.

ash does not support the read -p BASH extension.

ash does not support functions.

You need to rewrite your script without these things if you want it to run in ash.
# 3  
Old 08-23-2012
Quote:
Originally Posted by Corona688
ash does not support the read -t BASH extension.

ash does not support the read -p BASH extension.

ash does not support functions.

You need to rewrite your script without these things if you want it to run in ash.
OK, I'm not arguing but.....

The function is getting called correctly else I wouldn't be getting to the CTR-c detected text.

The identical read statement is working perfectly in an ash busybox on the same machine, it's just not working inside the function. i.e. What I did was separate out just the read command to it's own script and tested it.
# 4  
Old 08-23-2012
Quote:
Originally Posted by tesser
OK, I'm not arguing but.....

The function is getting called correctly else I wouldn't be getting to the CTR-c detected text. The identical read statement is working perfectly in an ash busybox on the same machine, it's just not working inside the function. i.e. What I did was separate out just the read command to it's own script and tested it.
Show your entire code, then. It's probably the way the function's being called, redirections and such, preventing it from reading standard input.
# 5  
Old 08-23-2012
[edit] Ignore that. Far too early in the morning. My apologies.

Also, thanks for teaching me things I didn't know about ash. I have confirmed that it supports all the things you show. It having functions makes it a much more useful shell than I realized.
# 6  
Old 08-23-2012
Quote:
Originally Posted by Corona688
[edit] Ignore that. Far too early in the morning. My apologies.

Also, thanks for teaching me things I didn't know about ash. I have confirmed that it supports all the things you show. It having functions makes it a much more useful shell than I realized.
Morning????

Bruddy Canucks Smilie

I think your point about a redirect could be it though.....

I'm abit out of my comfort zone on the subtleties of redirects.

Could it be due to the fact that the function is getting called inside the loops that stops the read working?

So in a nutshell....

start loop 1

Lets pick which set were going to work on

start loop 2

lets collect and analyse the data from set chosen in loop 1 till we get a match or a terminating match.

now setup our Ctl-C function to allow us manual exit

end loop 2 - No matching conditions found yet so go round again.

end loop 1 - we've finished working on that set so let's pick another one.
# 7  
Old 08-23-2012
I tested this snipplet on busybox 1.19.4 and it works as expected.

So as Corona688 requests, I also must ask how the trap is being called. If there are redirections affecting stdin, maybe read is operating on /dev/null, in which case, it would just carry on since that's your default case statement and KEYHIT would be null...

Edit: My reply took too long.. Is your loop operating as,

Code:
while ...; do
...
done <file

I wonder what read works on then? Smilie

Maybe try read ... </dev/tty inside your trap
These 2 Users Gave Thanks to neutronscott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

This function (decode64) runs on gawk but not on busybox awk

Hello, I'm trying to figure out a way to use a decode64 function in an embedded system who has few utilities, including busybox. Right now have something like this (taken from "google base64-and-base85-encoding-awk-scripts" sorry, I'm not able to post urls yet) _decode64() { &&... (4 Replies)
Discussion started by: chilicuil
4 Replies

2. Shell Programming and Scripting

Simple grep is not working properly on busybox

Hi, I'm trying to write shell scripts on busybox bash on windows and grep is not working for simple regular expression like $ grep FEN * bash: grep: Invalid argument but the same grep works fine if use the single file instead of asterisk $ grep FEN test $ Am I doing something... (5 Replies)
Discussion started by: prvnrk
5 Replies

3. Shell Programming and Scripting

Getopts inside a function is not working

Hi All, I am using geopts inside a function in shell script. But it is doesnt seem to read the input args and I always gt empty value in o/p. my code is http://sparshmail.ad.infosys.com/owa/14.2.318.4/themes/base/pgrs-sm.gif This message has not been sent. #!/bin/ksh IFS=' '... (1 Reply)
Discussion started by: prasperl
1 Replies

4. Shell Programming and Scripting

If loop inside function not working.

check_deplver () { dir=/abc/def/ghi if ssh -o StrictHostKeychecking=no $1 "" 2> /dev/null then echo " output is " ssh -o StrictHostKeychecking=no $1 "ls -lrt $dir | grep -i abc" 2> /dev/null else echo " directory not presnt" fi } This is not working. But... (7 Replies)
Discussion started by: NarayanaPrakash
7 Replies

5. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

6. Web Development

CGI not working with httpd server on busybox 1.15.0 on ltib Linux 2.6.34 (404 page not found)

I have some industrial ARM linux board with 2.6.34 Linux on it with Busybox v1.15.0. The https.conf is located in /etc/ and contains: H:/root/web In the www directory I also have 'cgi-bin' folder with chmod 777 and in that folder a file called 'testcgi'. Now I start the server with... (1 Reply)
Discussion started by: Roboserg
1 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Shell Programming and Scripting

read statement not working in a function

Pls this is emergency.I have written a script which is taking input from another script. and the contents of my second script are acting as functions to my main script.Now the problem is that in one of the functions i want the script ececution to stop and start when user enters any character r... (2 Replies)
Discussion started by: sumitdua
2 Replies

9. Shell Programming and Scripting

sudo command is not working inside a script when placed in cron

Hi All, i have a cron entry like 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /amex/sssmonitor/dss_chk.ksh and the script is like #!/bin/ksh file=`uname -n` > /sunmast/projects/oasis/COREDEV/Dss$file.log > /tmp/output_sss today=`date` varb=`ps -ef | grep... (5 Replies)
Discussion started by: usha rao
5 Replies

10. Shell Programming and Scripting

read command (input) inside the while loop

Hi, 'read' command is not working inside the while loop, How can I solve this? Rgds, Sharif. (2 Replies)
Discussion started by: sharif
2 Replies
Login or Register to Ask a Question