bash - how to launch a console window via script and execute commands in it?
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.
bash - how to launch a console window via script and execute commands in it?
Hi,
I'm not that familiar with bash scripting.
I have a script that launches via MIME from Firefox, with a custom extension. It works okay.
The script also works to open a console and run the script manually from a commandline. But, I want the script itself to open the console and then execute the commands within the console.
I have been able to have a single command open in a konsole window like this:
konsole gpg [etc.]
I think I can do this:
konsole echo "what the heck?"
But I want to do this:
konsole
echo "what the heck"
echo "i have no idea what I'm doing"
echo "so this window will close."
gpg -e [etc]
(Konsole could be replaced by xterm or whatever. Konsole is from KDE.)
Of course, as you know, the above script wouldn't work because the console opens, closes, and then the echo commands all happen without writing to a console at all so I won't see them.
I want the execution to happen in the konsole window.
Any thoughts? I've browsed a bit through various bash and linux scripting manuals, but I haven't been able to find what I am looking for.
execute or run script in a new terminal bash or xterm.
even from a menu. I entered this into the fluxbox menu and a new terminal / bash window opens and the script is run - no need to even cd to the folder and seemingly no need for a & at the end either. the & symbol at the end is supposed to keep it running and then keep running the next commands when in a list of commands or a script. ie..
cd home/blabla/.runme1.sh &
cd mousepad /usr/blabla.txt &
cd another/place/script.sh
sudo mousepad /etc/fstab
So the first 2 lines of this script will run the script and then move on to the next line but the 3rd line hasn't got the 'and' (&) symbol so waits until that command is complete until continuing.
how to pause script execution -- new problem, same project
Well, all worked out while I was using KDE3.5 and I was able to create the script I wanted.
Now all of a sudden, along comes KDE4.0 and my script won't work anymore, which seems strange to me, since presumably bash execution does not relate to the desktop software?
So, as far as I can tell, when I am running KDE4.0, this script does not "pause" to wait for the next command. That is, apparently the "odt" file is re-encrypted and removed before soffice actually executes.
Whereas, when I am running KDE3.5 I can unencrypt the file via gpg, the script launches OpenOffice to edit the file -- and waits until I exit OpenOffice to re-encrypt and remove the odt file.
How do I get my script to wait until one task completes before commencing the next task?
Thx.
Anyway, here's my script:
#!/bin/bash
# launchodt
#
#script to launch encrypted odt file
#
if [ -e "$1.odt" ]
then
echo "file exists"
else
echo "file don't exist"
konsole -e gpg -o $1.odt $1
fi
if [ -e "$1.odt" ]
then
soffice -writer $1.odt
gpg -e -r client $1.odt
fi
if [ -e "$1.odt.gpg" ]
then
rm $1.odt
mv $1.odt.gpg $1
else
echo "File did not encrypt!!!"
fi
partially solved (launch terminal and execute via bash script)
Okay, I ran my script from another script that launches it in x-term. So, then I see an error that indicates a "session manager" failure and that bash failed to open a network socket. So, that would explain why the script simply forges ahead. This would seem to be a KDE4.0 problem, since I don't have the same thing in KDE3.0. Some other observations are that when I launch the script from the Dolphin file manager, everything runs extremely slowly (including OpenOffice save & exit). When I launch the script from the Konqueror filemanager, everything executes quickly. Just a bit of trivia someone else might be interested in.
I put a "read" command into my script, and so I can pause execution until a manual response.
But, this is not an elegant solution.
So, anyone with some better suggestions for automating the process?
Also, it's not clear to me why gpg will not open a dialog box when the script calls it without a terminal, but when I call gpg via a terminal command, then I get both an open terminal >and< a separate (more attractive) dialog box ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.