Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
My default ~/.bashrc (in Debian) sets the console prompt by changing the environment variable PS1. The script also sets the console's title (showing username and pwd) by:
PROMPT_COMMAND='echo -ne "\033]0;some text here\007"'
Now, I have a shortcut on my (KDE) desktop to a script running in Konsole. I want to be able to change Konsole's title in that script. But it doesn't work using either the PS1 variable or the PROMPT_COMMAND. From the command prompt I can easily change the title using either method, just not from a script.
What am I doing wrong? How can I change the title in a script?
(I know that I can change the latter part of the title, default "Shell", by the command:
dcop #KONSOLE_DCOP_SESSION renameSession "some text"
but that's not the renaming I'm looking for.)
Distribution: openSuSE 42.1_64-KDE, Ubuntu 14.04, Mint 17.2
As I understand the mechanism, a script doesn't call a new instance of bash but is executed in the old one, so maybe here is the reason for your problem. So, I'd try to first call bash in your script and then do the rest to the new shell.
<edit>Oops, sorry, didn't read in sufficient detail. Since you are not starting from the shell maybe this is not the reason after all. Then again, it would be the login-shell...
As JZL says, I think a script is opened using the currently defined title, so if the frist script simply opened Konsole, changed the name for the Konsole, and then called the second script which actually does the stuff you want?
That way, by the time the second script is called, the name has already been changed, therefore (I think) it should open with the new title?
I think if it is a global title, you could even call a third script (or add it the end of the second) to change the global title back to the defaults, so all other Konsole's don't open with the custom title.
Originally posted by JZL240I-U As I understand the mechanism, a script doesn't call a new instance of bash but is executed in the old one, so maybe here is the reason for your problem. So, I'd try to first call bash in your script and then do the rest to the new shell.
<edit>Oops, sorry, didn't read in sufficient detail. Since you are not starting from the shell maybe this is not the reason after all.
But even if it called a new instance it wouldn't matter, right? Any instance of bash would first run ~/.bashrc, where the (typical) PS1 assignment and PROMPT_COMMAND is done. The problem being of course, that I can't change the PS1 variable in a script (other than ~/bashrc).
I'm sure there's something fundamental that I don't understand here...
If I run the PS1=.. line directly in the shell, it changes the console title to "penguin" and makes the prompt look like "username@host:$ ". However, if I run the script the console title and the prompt looks just like it did before I ran the script. So the big Q is: how do I make the script work the way I want?
Originally posted by JZL240I-U My scheme (edited again simultaneously with your answer -> have a look ) would enable you to have a different title in the old spawning shell and in the shell just freshly spawned.
Distribution: openSuSE 42.1_64-KDE, Ubuntu 14.04, Mint 17.2
That's what I meant but did say wrong in my first post. Contrary to my assertion that a script runs in the same shell it is started from, it rather looks like it runs in a new (spawned) one. Thus it sets the variables for the new shell while you stare at your screen displying the old one from where you started the command.
I have something similar in my bashrc. It's not exactly the same, but it's based on the same idea (if i understand your question correctly).
What I'm doing is setting my PS1 according to what application is being run. When I run midnight commander, I want the prompt to be shorter than usual, so I use the alias
alias mc="export mcON=1; mc -b"
Then my PS1 is
if [ "$mcON" = "1" ]; then
First, what is that you are trying to change, your shell prompt or your xterm/konsole titlebar/window text? The word "title" has a different meaning from the world "prompt"? PS1 has the shell prompt & PROMPT_COMMAND is something which is executed just before next the shell prompt is displayed.
If you have a bash script, then anyway upon execution you would be seeing the output of the commands in the script & not the shell prompt (unless that spawns another bash shell). Anyway, I presume you wish to change the shell prompt. My test setup is below:
SF1B:/supmis> cat .bashrc
SF1B:/supmis> cat a
SF1B:/supmis> cat b
export PROMPT_COMMAND="export PS1=prompt_for_a\>"
However if you wish to change the window title, then the dcop route may be the way to do it.
I liked your first solution better - unfortunately, I couldn't get either to work. Besides, hacking .bashrc for specific applications/scripts seems like overkill for me.
Yes, I understand if the question is a little fuzzy - and excuse my mixing of terms. What I'm trying to do is to change the konsole titlebar. This can be done using the PS1 variable (or the PROMPT_COMMAND) and the \e] sequence, so you example could apply.
However, I tried your example and it didn't work. I added some (debugging) echos in the scripts and I saw that first PROMPT_COMMAND is exported, then a is executed. When a finish (i.e., exit) any statement after "exec a" is not run. Strange.
I'm getting a little bit tired and frustraded about rhi problem. I hate it when I don't understand why something doesn't work the way my logic tells me... Oh well, there's more to life.
Can someone tell me _why_ my script in post #6 doesn't work.
Also, the dcop route only changes the "middle" part of the titlebar. The titlebar looks like "something_changed_by_\e] - Shell No. N - Konsole". dcop changes "Chell No. N".
All you have to do is change the "exec a " with the script name you wish to execute. "exec" replaces the current shell with the command following it. So your current shell got replaced with "a" & that was the last command.