• which file should have my bash prompt, .profile vs .bashrc

    From Wolfgang Agnes@21:1/5 to All on Mon Dec 2 08:32:47 2024
    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!)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Elvidge@21:1/5 to Wolfgang Agnes on Mon Dec 2 12:49:58 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Wolfgang Agnes@21:1/5 to Chris Elvidge on Mon Dec 2 13:38:25 2024
    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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Elvidge@21:1/5 to Wolfgang Agnes on Mon Dec 2 20:39:56 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lowell Gilbert@21:1/5 to Wolfgang Agnes on Mon Dec 2 21:50:40 2024
    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/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Shepelev@21:1/5 to All on Fri Dec 6 13:19:18 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)