LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   shell behaves differently in rl5 and rl3 (https://www.linuxquestions.org/questions/linux-general-1/shell-behaves-differently-in-rl5-and-rl3-233468/)

Warmduvet 09-21-2004 02:21 PM

shell behaves differently in rl5 and rl3
 
Hi I'm running rh9.0 and at the moment I am playing with sed. I have put a function in my .bash_profile so that it would be available and not have to be declared every session. However the function only runs in rl3 at the shell prompt
In rl5 typing in the function name and arguments just returns me to the prompt no error message nothing. In rl5 I'm using xterm and rh default terminal program.

any help appreciated.

WD

Tinkster 09-21-2004 02:54 PM

G'day mate :}

Create a .bashrc and source .bash_profile from there.

Alternatively, invoke as "xterm -ls" to make it a login
shell ... if you want to understand why, read
Code:

man bash
/INVOCATION



Cheers,
Tink

Warmduvet 09-21-2004 03:38 PM

thanks Tink, is there a way to set bash to start with "bash --login" so I dont have to type it in every time? same with xterm -ls.

Can I put "bash --login" in my .bashrc file?

WD

btmiller 09-21-2004 04:19 PM

You could do that, but I personally just redirect my .bash_profile to .bashrc -- the following are the contents of my .bash_profile:

Code:

if [ -r ~/.bashrc ]
then
  . ~/.bashrc
fi

and then I put all of my customized setup stuff into my .bashrc file. This way it gets run regardless of whether or not I'm invoking a login shell.

Warmduvet 09-21-2004 04:43 PM

Yeah I have something similar in my .bash_profile

if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi

Tinkster 09-21-2004 05:02 PM

You need it the other way round mate, since
.bash_profile won't be pulled if it's not a login
shell which in your case it isn't.


If it's NOT a login-shell bash only evaluates
~/.bashrc



Cheers,
Tink

Warmduvet 09-21-2004 07:04 PM

slight problem, I put "bash --login" in my .bashrc file and now I can't login as root :eek:

nor can I su - root from other user any suggestions...
yes I know I shouldn't have been working in root :o

my .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:$HOME/bob/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"

export USERNAME BASH_ENV PATH
function testfind ()
{
echo "first argument: $1"
echo "second argument: $2"
sed -n "/$1/p" $2
}

My .bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ls='ls --color=yes'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

bash --login



WD

Tinkster 09-21-2004 07:12 PM

Boot into single user mode and edit it from there ...

If that fails, boot of CD (rescue mode).

Other (possbile) work-around:

su -c "mv ~/.bashrc ~/.bashrc.bad"


Cheers,
Tink

Warmduvet 09-21-2004 07:15 PM

booting to rl3 doesnt work can't login as root

dont I need to be root to do the mv?

Tinkster 09-21-2004 07:17 PM

Just try it :) It's all one line!


I won't f*ck up root account just to verify that
it works ;}


Cheers,
Tink

Warmduvet 09-21-2004 07:22 PM

LOL

OK it worked:D

still leaves me with ny original problem... and both .bashrc and .bash_profile

have

if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi

so it shouldn't matter wether the shell is interactive or login

WD

Tinkster 09-21-2004 07:38 PM

OK, let's get that straight ...

:}


You need to source .bash_profile
from .bashrc for the modifications in
.bash_profile to be working in the xterm.

Sourcing .bashrc from both .bashrc and
.bash_profile won't give you any benefit.

If it's not a login shell .bash_profile won't
be pulled at all.


Cheers,
Tink

P.S.: I think I definitely deserve an affero after all this ;)

Warmduvet 09-21-2004 09:15 PM

OK affero done.

I understand what you mean by source .bash_profile and why,
I,m not sure how.
Do I replace...


in .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

with

# Source global definitions
if [ -f ~/.bash_profile ]; then
~ /.bash_profile
fi

???

WD

Tinkster 09-21-2004 10:07 PM

Got that right :)


Cheers,
Tink

Warmduvet 09-22-2004 12:09 AM

Ok I tried..

# Source global definitions
if [ -f ~/.bash_profile ]; then
. ~ /.bash_profile
fi

no luck, and login failed
and..

source ~/.bash_profile

no luck, and login failed
and..

ln -s /home/bob/.bashrc /home/bob/.bash_profile

this gave message ln : `/home/bob/.bash_profile': file exists
but login didn't fail but also didn't achieve desired result.

I have done quite a bit of googling and this seems to have been aproblem
for a few people but the solution never seems to be arrived at :scratch:

WD


All times are GMT -5. The time now is 01:07 AM.