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

Re: OT: Exporting a BASH prompt from a script



* 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------

HTH
George



Reply to: