[SOLVED] Running Bash script - Output can't be seen because command window closes
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.
read -t 20 || exit
read -p "Press <enter> again to close "
The script won't terminate until the first read times out in 20 seconds. If you press <enter> during that time, then the second read will wait forever for another <enter>.
Why is this script doing this. Most of the ones I write don't present this sort of behavior.
See this script which acts normally.
Code:
#!/bin/bash
#Sun 24 Sep 2017 18:23:28
# This is the companion script to mydb-mysqldump.sh
# mydb-mysqlrestore.sh will restore the files dumped by that program
#File: DB-Web/mydb-mysqlrestore.sh
folder="/home/rick/DB-Web/mydb-bakup-folder"
# if gzip files unzip them
find "$folder" -type f -iname '*gz' -exec gunzip {} +
echo "-- Start"
echo
echo -- Restoring --
echo
for I in $(ls -d "$folder"/* )
do
echo "$I" | awk -F_ '{print $2}'
mysql -urick -prick < $I
done
echo
echo "-- Finish"
What matters is how the script is invoked. If either script is run from an existing command window, then that window will remain open when the script exits and returns control to that command shell**. But, if you launch the script from a menu or a desktop launcher configured as "Run application in a terminal", then there is no shell to return to and the window will close immediately when the script exits. The commands I suggested provide a way to keep such a terminal window open.
** If the command you type is "exec path/to/script", then the invoking shell is overlaid by the one running the script and the window will close immediately upon termination.
Is there a way to not have the 'baby' command window to show the output of a script run through the launcher.
If I can't get the regular display to show output is there a way to change font etc from the 'baby' window. See attachment for what I'm talking about. you have to use a magnifying glass to read Enter Password:
I have no idea what do you mean by baby window. You can redirect the output of your shell script into file and use a text editor to check the content (of that file).
Is there a way to not have the 'baby' command window to show the output of a script run through the launcher.
If I can't get the regular display to show output is there a way to change font etc from the 'baby' window. See attachment for what I'm talking about. you have to use a magnifying glass to read Enter Password:
It's just using the default terminal. Open the default terminal yourself, change the default font, and that should change it for your script.
It's just using the default terminal. Open the default terminal yourself, change the default font, and that should change it for your script.
The default terminal has a white background with black text and a menu with a number of options. The one that shows up when you use the launcher has a black background with white text and a minimal menu where all you can do is change the size a little bit.
Seems like you have more than one terminal emulater (i.e. "animal" ) installed on your system.
Open a terminal and before and when that problematic script is running enter:
Code:
ps ax
Then compare the outputs. There should be two lines more in the second output. One is the script and one is the terminal emulator used for that script. Then you may be able to start that other terminal emulator (because now you know it's name) and change it's settings.
Another way might be changing the default terminal emulator. On my Debian based system the link is /etc/alternatives/x-terminal-emulator. Should be similar on Ubuntu. Do (assuming the path is the same):
Code:
ls -l /etc/alternatives/x-terminal-emulator
to see what it points to and compare it to the name of your usual terminal emulator.
your op says "output can't be seen because command window closes" but now we can see it.
so, we moved on to the next problem, which is too small font?
you can either edit the script, or, since this is clearly xterm in the scrot, you can make a quick web search on how to change xterm's font size. it can even use ttf/otf fonts.
There's many solutions, including forgetting the "Application in Terminal" altogether and just run mate-terminal with the -e option but I wanted to have my cake and eat it, too. And it's a one-time command:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.