[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 07:58 pm, Georg Drees wrote:
> * On Sat, 26 Mar 2005 19:40:36 -0500, Hal Vaughan
>
> <hal@thresholddigital.com> wrote:
> > 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.
>
> [...]
>
> > > > 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>
>
> [...]
>
> > 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.
>
> IIRC, at http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ they use a
> function in the script-file, then source the script and call the
> function, like
>
> $
> $cat ./myprompt
> function prompt_command {
> PS1="\u@\h:\w\$"
> }
> $source ./myprompt
> $prompt_command
> user@host:~$echo "above untested example"
>
> now, you could simply put that into your .bashrc (or was it
> .bash_profile, I still mix those two up :-S I enable the sourcing of
> .bashrc from .bash_profile and put my interactive things into .bashrc,
> but dunno if that the RightThing(tm) to do)
> ---snip .bash<whatever>---
> #something else
> . ~/myprompt
> prompt_command
> #something different
> ------snap------

I had even tried this, and it wasn't working.  I had to power down to check on 
some connections in the box, and when I rebooted, the very things I was doing 
before were working perfectly.

Strange.

But I won't complain, and if it starts up again, I'll probably be back here 
asking for help on it again.  ;)

Hal

>
> HTH
> George



Reply to: