[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

using `myscript.sh` to change current env



I want to have a script, to change between a few prompts per the arg
supplied. This is so I can quickly change from my glorious
bells-and-whistles prompt to a plain prompt (eg for cut and paste to
debian-user, just "$ " or "# " depending on current user) to a
timestamped prompt (when I have some long-running process, and I want
to see when it finished) etc.

In bash, we cannot run a script plainly, and have that script update
the current shell's env.

We could source the script with 'source' or '.' command, but this
requires a correct location of the script to be entered, which is slow
and not ideal. I want to be able to run the script as a command.

So I thought, run the script in a subshell, executing the result, like:
$ `ps1`

The following 3-line script is meant to test exactly this:

#!/bin/bash
PS1=': '
echo "export PS1=$PS1"

Note that in this example, the desired new prompt is a colon followed
by a single space.
The problem is, when I run this script as `ps1`, I get a changed
prompt, but just to colon, not including the space.

Does anyone know how I might have a space character included in my new
prompt, using this `way` to change my prompt?

TIA
Zenaan


Reply to: