I have a script that has to execute a read command in a function, this is in an ash busybox.
The code is...
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.
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.
[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.
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,
Yes, exactly, if that code is operating inside a loop like that, it will read from the file and not from the terminal. </dev/tty will always read from the terminal -- if you have a terminal, that is.