Why can’t I change my Linux terminal environment from a script

I wanted to configure my terminal sessions, with a tab label to say what the window is, and colour them, so I get a visual clue.

For example I have a script

PS1='[\e]0;Opentel\a]\u@\$ '
docker run --rm --name ozf \
...
otel/opentelemetry-collector-contrib:latest --config opentransform.yaml

If I enter the PS1 command in the window – it changes tab’s label.

If I put it in a shell script, I execute the commands to change my tab and run the docker image, but it does not change the tab’s label. Why not?

  • The source command (or the . command) treats the commands in the file, as if I had entered them at the terminal.
  • With the bash or shell, the command creates a new shell, and then executes commands inside it. Once the command finishes, the shell is destroyed, but the original shell is unchanged.g

Another of the it is obvious when you know the reason.

Leave a Reply