Find the answer to your Linux question:
Results 1 to 3 of 3
Hello all, I can't remember the correct way to do this, I want to have a /etc/bashrc that says if there is a $user/.bashrc then use it, else use /etc/bashrc ...
  1. #1
    Linux Newbie AboveNBeyond's Avatar
    Join Date
    Mar 2007
    Posts
    120

    if and else .bashrc help please...

    Hello all,
    I can't remember the correct way to do this, I want to have a /etc/bashrc that says if there is a $user/.bashrc then use it, else use /etc/bashrc

    Is this close?
    if [ -f $user/.bashrc ]; then
    $user/.bashrc
    fi

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Well, let's look at what you're doing:

    Your test is nearly correct. What do you believe the value of $user to be? It does not contain what you think it contains.

    Also, you are saying "If this file exists, then execute it". This is not what you want: you want to source the file, not execute it.

    Finally, note that after you handle the user's bashrc, you fall through on the if, and will continue to process the /etc/profile. So you will want some way to ensure that only one or the other happens.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Linux Newbie AboveNBeyond's Avatar
    Join Date
    Mar 2007
    Posts
    120
    Hi Cabhan,
    My thought is this...
    If there is a .bashrc file in a users home dir then use it, if not then use /etc/bashrc, just not both.

    if [ -f ~/$USER/.bashrc ]; then
    ~/$USER/.bashrc
    else
    /etc/bashrc
    fi
    Is my thought? Is that closer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...