There might be simpler ways around this.
In many desktop environments, you can run an arbitrary command via the GUI. A common shortcut for this is AltF2. Just run gnome-terminal -x sleep 10h
.
Or: Login to a TTY (CtrlAltF1-F6). Run DISPLAY=:0 gnome-terminal -x sleep 10h
.
Or: You might have another terminal emulator installed, say xterm
. Run it, and then gnome-terminal -x sleep 10h
.
Or:
- Open your file manager, and go to
/usr/share/applications
- Find
gnome-terminal.desktop
, and copy it somewhere (your ~/Desktop
, or ~
, etc.)
- Edit the copy (probably can be done by right clicking and choosing Open With, and then picking an editor)
- Change
Exec=gnome-terminal
to Exec=gnome-terminal -x sleep 10h
- The copied file should be showing the GNOME Terminal icon. If it isn't, right click it, go to Properties and ensure that it is executable.
- Double-click the copy to execute it, which should launch an instance of GNOME Terminal running
sleep 10h
.
You now have 10 hours to undo whatever you did.
The script works by setting the shell's interactive prompt to a string which includes control codes to manipulate the xterm
window title. Each time the shell's prompt is displayed, the control codes to change the window title are output.
But of course, inside a script, no interactive prompt is ever displayed, so these commands have no observable effect (though if you started another interactive shell from within the script, you could see the window title change). And because no script can change the environment of its parent process, the change is lost once your script terminates.
Anyway, from your script, you could of course print out the control codes directly.
printf '\033]2;Hello\a'
This changes the window's title once, but if any other program later changes it again, your old title will be lost. The trick to change your prompt is widespread because some popular programs in the past would often change your window title soon after you changed it to your liking (though I don't think this is a common problem any longer). The drawback is that if something has a genuine reason to change your window title, that will now be superseded as soon as your shell displays its prompt again.
If you want code to change your current shell's prompt, you can't put those in a regular script; but you can source
the script file, or put the commands in a shell function instead (commonly done in your Bash profile in order to make it persistent).
Incidentally, the Bash prompt should include additional control codes to tell Bash when a part of the prompt is effectively zero width, as far as calculating the display width of the prompt is concerned. You will find that line wrapping is erratic if you type a long command and then need to backspace, for example; Bash will attempt to redraw the prompt, but does it in the wrong place, because it thinks the screen control codes contribute to the prompt's width. You'll want to add these \[
and \]
Bash control codes around them.
PS1="$ORIG\[$TITLE\]"
(The curly braces aren't really contributing anything, and hamper legibility, so I took them out.)
Best Answer
Your command substitution will generate a string.
In the case of
this string will be
"hello " "hi and bye"
.The string is then undergoing word splitting (and filename globbing, but it doesn't affect this example). The word splitting happen on every character that is the same as one of the characters in
$IFS
(by default, spaces, tabs and newlines).The words generated by the default value of
IFS
would be"hello
,"
,"hi
,and
, andbye"
.These are then given as separate arguments to your script.
In your second command, the command substitution is
This generates the string
hello hi and bye
and the word splitting would result in the four wordshello
,hi
,and
, andbye
.In your last example, you use the two arguments
hello
andhi and bye
directly with your script. These won't undergo word splitting because they are quoted.