Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You like to form new friendships and make new acquaintances.


comp / comp.unix.bsd.freebsd.misc / Re: which file should have my bash prompt, .profile vs .bashrc

SubjectAuthor
* which file should have my bash prompt, .profile vs .bashrcWolfgang Agnes
+* Re: which file should have my bash prompt, .profile vs .bashrcChris Elvidge
|`* Re: which file should have my bash prompt, .profile vs .bashrcWolfgang Agnes
| `- Re: which file should have my bash prompt, .profile vs .bashrcChris Elvidge
`* Re: which file should have my bash prompt, .profile vs .bashrcLowell Gilbert
 `- Re: which file should have my bash prompt, .profile vs .bashrcAnton Shepelev

1
Subject: which file should have my bash prompt, .profile vs .bashrc
From: Wolfgang Agnes
Newsgroups: comp.unix.bsd.freebsd.misc
Organization: A noiseless patient Spider
Date: Mon, 2 Dec 2024 11:32 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wagnes@example.com (Wolfgang Agnes)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: which file should have my bash prompt, .profile vs .bashrc
Date: Mon, 02 Dec 2024 08:32:47 -0300
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <874j3ml3q8.fsf@example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 02 Dec 2024 12:32:49 +0100 (CET)
Injection-Info: dont-email.me; posting-host="679685da1d6daad20e67a8fab5e2e8b9";
logging-data="3471555"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XnSz8Ri7wGIM2DGyYFMvixf0I2QmkLZQ="
Cancel-Lock: sha1:wrWiPwu3fcPFfCD8A7yJt5+tNRI=
sha1:BQehsfOsBDun3E9AwaBTBQsS/Xc=
View all headers

I installed bash and have been trying to set up my prompt. I notice
that if I add

PS1='# '; export PS1

to my .profile, then I get the prompt when I log in, not when I /sudo
su/ from a regular user. If I add

PS1='# '; export PS1

to ~/.bashrc, then I get the prompt when I ``sudo su'', but not when I
log in. I can add the prompt set up to both files, but I'm asking
myself---how do you guys avoid such redundancy? (Thanks!)

Subject: Re: which file should have my bash prompt, .profile vs .bashrc
From: Chris Elvidge
Newsgroups: comp.unix.bsd.freebsd.misc
Organization: A noiseless patient Spider
Date: Mon, 2 Dec 2024 12:49 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@internal.net (Chris Elvidge)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: which file should have my bash prompt, .profile vs .bashrc
Date: Mon, 2 Dec 2024 12:49:58 +0000
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <vikadn$3b35f$1@dont-email.me>
References: <874j3ml3q8.fsf@example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 02 Dec 2024 13:50:00 +0100 (CET)
Injection-Info: dont-email.me; posting-host="83b0557600b172a9e9bf2d22c7faa7e1";
logging-data="3509423"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bqXjqo+vO4f1JhFJS0qM4Cko9/2F1zHg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:hkZKnZy4v04UFYiJi7AfkNTbW2M=
In-Reply-To: <874j3ml3q8.fsf@example.com>
Content-Language: en-GB
View all headers

On 02/12/2024 at 11:32, Wolfgang Agnes wrote:
> I installed bash and have been trying to set up my prompt. I notice
> that if I add
>
> PS1='# '; export PS1
>
> to my .profile, then I get the prompt when I log in, not when I /sudo
> su/ from a regular user. If I add
>
> PS1='# '; export PS1
>
> to ~/.bashrc, then I get the prompt when I ``sudo su'', but not when I
> log in. I can add the prompt set up to both files, but I'm asking
> myself---how do you guys avoid such redundancy? (Thanks!)
>

Put it in .bashrc and then call .bashrc from .profile (unless
..bash_profile exists; only for bash.)

e.g.
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

..profile is called by a login shell
..bashrc is called by interactive bash shell

--
Chris Elvidge, England
I WILL NOT SNAP BRAS

Subject: Re: which file should have my bash prompt, .profile vs .bashrc
From: Wolfgang Agnes
Newsgroups: comp.unix.bsd.freebsd.misc
Organization: A noiseless patient Spider
Date: Mon, 2 Dec 2024 16:38 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wagnes@example.com (Wolfgang Agnes)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: which file should have my bash prompt, .profile vs .bashrc
Date: Mon, 02 Dec 2024 13:38:25 -0300
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <87a5dejb0e.fsf@example.com>
References: <874j3ml3q8.fsf@example.com> <vikadn$3b35f$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 02 Dec 2024 17:38:25 +0100 (CET)
Injection-Info: dont-email.me; posting-host="679685da1d6daad20e67a8fab5e2e8b9";
logging-data="3623847"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1984AohqGdv50q537B9x2/aMEnR/40NcLA="
Cancel-Lock: sha1:Y4diHfDo/BA8COWmOvJvcN3XuW8=
sha1:L4diXsZWwGXGK0NwyzZBphmj2q0=
View all headers

Chris Elvidge <chris@internal.net> writes:

> On 02/12/2024 at 11:32, Wolfgang Agnes wrote:
>> I installed bash and have been trying to set up my prompt. I notice
>> that if I add
>> PS1='# '; export PS1
>> to my .profile, then I get the prompt when I log in, not when I
>> /sudo
>> su/ from a regular user. If I add
>> PS1='# '; export PS1
>> to ~/.bashrc, then I get the prompt when I ``sudo su'', but not when
>> I
>> log in. I can add the prompt set up to both files, but I'm asking
>> myself---how do you guys avoid such redundancy? (Thanks!)
>>
>
> Put it in .bashrc and then call .bashrc from .profile (unless
> .bash_profile exists; only for bash.)

Is this how it's typically done? I thought that sourcing .profile, say,
from .bashrc would destroy the purpose of having a separate thing for
when logging in and another for interactive runs of the shell. Now
realize I could make a library-script and source it from both scripts
(.profile and .bashrc), but then I've never done that myself and so I
was wondering how people do things.

Anyway, thanks very much for sharing your side of things!

Subject: Re: which file should have my bash prompt, .profile vs .bashrc
From: Chris Elvidge
Newsgroups: comp.unix.bsd.freebsd.misc
Organization: A noiseless patient Spider
Date: Mon, 2 Dec 2024 20:39 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris@internal.net (Chris Elvidge)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: which file should have my bash prompt, .profile vs .bashrc
Date: Mon, 2 Dec 2024 20:39:56 +0000
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <vil5ut$3ic43$1@dont-email.me>
References: <874j3ml3q8.fsf@example.com> <vikadn$3b35f$1@dont-email.me>
<87a5dejb0e.fsf@example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 02 Dec 2024 21:39:58 +0100 (CET)
Injection-Info: dont-email.me; posting-host="851009f107b11d69a95a03c84804a590";
logging-data="3747971"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yVHH3HqSPeYq4Vtv0AaTvoGvUyW6J1i0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:HatPvQ48/Oi6013zGa6LCC4PI+g=
Content-Language: en-GB
In-Reply-To: <87a5dejb0e.fsf@example.com>
View all headers

On 02/12/2024 at 16:38, Wolfgang Agnes wrote:
> Chris Elvidge <chris@internal.net> writes:
>
>> On 02/12/2024 at 11:32, Wolfgang Agnes wrote:
>>> I installed bash and have been trying to set up my prompt. I notice
>>> that if I add
>>> PS1='# '; export PS1
>>> to my .profile, then I get the prompt when I log in, not when I
>>> /sudo
>>> su/ from a regular user. If I add
>>> PS1='# '; export PS1
>>> to ~/.bashrc, then I get the prompt when I ``sudo su'', but not when
>>> I
>>> log in. I can add the prompt set up to both files, but I'm asking
>>> myself---how do you guys avoid such redundancy? (Thanks!)
>>>
>>
>> Put it in .bashrc and then call .bashrc from .profile (unless
>> .bash_profile exists; only for bash.)
>

Slackware user here.

> Is this how it's typically done? I thought that sourcing .profile, say,
> from .bashrc would destroy the purpose of having a separate thing for

No. Source .bashrc from .profile only if $BASH_VERSION is set.
Also .bash_profile will not be used if shell is not bash.

> when logging in and another for interactive runs of the shell. Now
> realize I could make a library-script and source it from both scripts
> (.profile and .bashrc), but then I've never done that myself and so I
> was wondering how people do things.
>
> Anyway, thanks very much for sharing your side of things!
>

--
Chris Elvidge, England
I WILL NOT SPANK OTHERS

Subject: Re: which file should have my bash prompt, .profile vs .bashrc
From: Lowell Gilbert
Newsgroups: comp.unix.bsd.freebsd.misc
Organization: A noiseless patient Spider
Date: Tue, 3 Dec 2024 02:50 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lgusenet@be-well.ilk.org (Lowell Gilbert)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: which file should have my bash prompt, .profile vs .bashrc
Date: Mon, 02 Dec 2024 21:50:40 -0500
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <44frn5lbsv.fsf@be-well.ilk.org>
References: <874j3ml3q8.fsf@example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 03 Dec 2024 03:50:41 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a37c719008e4d59881f4c2169b35089c";
logging-data="3899552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192smGhLUJTzi/WcDEJgVQv"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:hW0/suDF3WcGTr41MA0OwTrgN54=
sha1:iu2f5iXKmbD6bxYpppGqOGVJoo4=
View all headers

Wolfgang Agnes <wagnes@example.com> writes:

> I installed bash and have been trying to set up my prompt. I notice
> that if I add
>
> PS1='# '; export PS1
>
> to my .profile, then I get the prompt when I log in, not when I /sudo
> su/ from a regular user. If I add
>
> PS1='# '; export PS1
>
> to ~/.bashrc, then I get the prompt when I ``sudo su'', but not when I
> log in. I can add the prompt set up to both files, but I'm asking
> myself---how do you guys avoid such redundancy? (Thanks!)

How you do this depends on how you use your shells. There are
"interactive" shells, and "login" shells, and .bashrc is only invoked
under specific conditions. See the bash manual for details, which
afford even more flexibility than most other shells.

Also note that .profile is read and executed by /bin/sh, should you
invoke that shell, and that on FreeBSD, /bin/sh is *not* bash.

--
Lowell Gilbert, embedded/networking software engineer
http://be-well.ilk.org/~lowell/

Subject: Re: which file should have my bash prompt, .profile vs .bashrc
From: Anton Shepelev
Newsgroups: comp.unix.bsd.freebsd.misc
Organization: A noiseless patient Spider
Date: Fri, 6 Dec 2024 10:19 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton.txt@g{oogle}mail.com (Anton Shepelev)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: which file should have my bash prompt, .profile vs .bashrc
Date: Fri, 6 Dec 2024 13:19:18 +0300
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <20241206131918.8a172855cbbedcb9b057723c@g{oogle}mail.com>
References: <874j3ml3q8.fsf@example.com>
<44frn5lbsv.fsf@be-well.ilk.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 06 Dec 2024 11:19:19 +0100 (CET)
Injection-Info: dont-email.me; posting-host="ccd74cc16cbed7850052930e8eeef166";
logging-data="2400845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eb6vDrDBd1/BG/eAzqFySygpqd2/M8bE="
Cancel-Lock: sha1:o7jbeHevBnPA+0Kcjt44PENbINs=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
View all headers

Lowell Gilbert:

> How you do this depends on how you use your shells. There
> are "interactive" shells, and "login" shells

In general, there are /four/ modes of shell:

interactive login
interactive non-login
non-interactive login
non-interactive non-login

Which .profile and .rc files are read when is usually
described in the manual for the shell, and I agree with
Wolfgang that the separation of initialisatio between
..profile and .rc scripts is not always clear and sufficient,
so that one has often to add conditional logic and invoke
one from the other.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

1

rocksolid light 0.9.8
clearnet tor