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

Re: OT: Exporting a BASH prompt from a script



On Saturday 26 March 2005 05:45 pm, Shreyas Ananthan wrote:
> Hal Vaughan <hal@thresholddigital.com> writes:
> > I'm having a strange problem.  I've installed some new systems and I can
> > change the prompt as I want, but if I write any kind of script, and
> > change the prompt within the script, it doesn't change the
> > prompt.  This is even with a short 1 line script that does nothing but
> > change the prompt.
> >
> > Here's the prompt I'm trying to use (which includes escape characters,
> > which seem to be causing the problem -- bash seems to see them as
> > commands):
> >
> > PS1="\e[35;40m[\u@\h:\W]\\$\e[0m "
> >
> > I know my old .bashrc changed the prompt (only PS1), but I don't remember
> > doing anything other than PS1="{my prompt}" to get it to do that.  Now it
> > won't work.  I tried to export PS1 so it would be available outside the
> > script, but export didn't like some of the characters in it.
> >
> > So how can I export a prompt I create in a script (like .bashrc) to use
> > outside the script (in normal command line)?
>
> When you run a script, it runs inside a new shell which is terminated
> when the script is completed. If you want the commands in the script
> to affect the current shell you want to do
>
> debian$ source ./<script name>
>
> instead of
>
> debian$ ./<script name>
>
> Hope that helps.

I wasn't aware of that point, however, even when I type "source scrptname", it 
still happens.

I think there's two problems: 1) it won't export the prompt (even when "source 
name" is used), and 2) Bash seems to be interpreting the escaped characters 
as commands.

Hal



Reply to: