[SOLVED] Bash script - Input command - Unable to read because error message
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically this script runs when I boot my device and wait for a input. The code itself works perfectly everything is just starting perfect and when I exit any of the soft it just come back to the script and wait for the next input.
The problem I have is that for example when I start Kodi and watch something and then Exit Kodi after I have some error message (see the pic). And basically the script is still running and wait for a Input. Problem is that I can't read the script anymore (the ECHO part at the top of the script) because of this error message that take all the space if I can say so.
My question is : Is there any way to clear the screen so I'm able to read the script after I exit my soft ? Or when I launch something and then exit to relaunch the script again ?
Possible to know when a process is killed and then relaunch the script ? Or maybe do a variable with the echo part and launch the variable when exit a soft
I don't really have a idea. If anyone can help
Thank you very much and sorry for the title if it is not that accurate was hard to find something to explain that...
the two functions input and start_kodi invoke each other, it is not really a good idea.
You need to invoke start_<something> from your input function, but you need to return from those funtions back to input instead of invoking it again.
You can do something like this:
Code:
input() {
while :
do
read -s -N 1 answer
case "$answer" in
....
done
}
start_kodi() {
kodi
# no need to call input, just return, but probably need to reset environment
reset
}
I'm not really sure if that solves this issue but probably helps.
the two functions input and start_kodi invoke each other, it is not really a good idea.
You need to invoke start_<something> from your input function, but you need to return from those funtions back to input instead of invoking it again.
You can do something like this:
Code:
input() {
while :
do
read -s -N 1 answer
case "$answer" in
....
done
}
start_kodi() {
kodi
# no need to call input, just return, but probably need to reset environment
reset
}
I'm not really sure if that solves this issue but probably helps.
Hey there
The script is working. But when I leave Kodi the screen is empty and waits for the next input. But I can't read the echo part as everything is just cleared
Thanks
EDIT : I actually added
echo "TEST1"
echo "TEST2"
echo "TEST3"
after RESET and as I said the screen is cleared but it shows the TESTS
Can we maybe variable the echo a the beginning and send this variable after the reset ?
I'm sorry, but I do not understand what did you ask.
From the other hand your script probably works, or more-or-less does what you expect, but not really correct. cyclic calling functions into each other is not a good idea and may cause difficulties. Also returning back (instead of further invocations) may solve some issues.
Kodi is very drastic, that means it grabs all the resources, reconfigures them for its own needs so probably you cannot simply continue afterward, you may need to restore everything.
Maybe I wasn't clear actually. I modified the script like you wrote it. with the reset and everything. The script works but once I exit Kodi the screen is cleared and the script wait for the next input and the problem remains. I can't see the menu (echo command at the top).
So for some test I added some echo command to see if the text would appear and it actually does appear. So what I did also is that I put the menu text into a .txt file and I use a variable like this :
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.