bash function problem, unless su is used - please help!

bash function problem, unless su is used - please help!

Post by Zsol » Sat, 07 Jul 2001 22:34:55



Hi All,

I have a weird problem with the bash shell (rpm: bash-2.04-18mdk, default of Mandrake 8.0).
The shell functions, that I define in my .bashrc do not work from an Xemacs window. They
used to work in Mandrake 7.2, and they still work if I use 'su myself' command first, then
start xemacs. So, somehow the 'su' command makes it OK, but without that, the function
are not visible from Xemacs (I want to use the functions in the compile command in xemacs).

Could someone help me with this problem, please ?
What is the difference between a terminal window shell environment and the one I get after
an 'su' command (for the same user)?
What configuration or setup files could be responsible for the lack of bash function inheritence to
the xemacs sub-shell ?

Thanks a lot in advance,
Zsolt

 
 
 

bash function problem, unless su is used - please help!

Post by Swif » Sat, 07 Jul 2001 23:05:52



> I have a weird problem with the bash shell (rpm:
> bash-2.04-18mdk, default of Mandrake 8.0).
> The shell functions, that I define in my .bashrc do not work
> from an Xemacs window. They used to work in Mandrake 7.2, and
> they still work if I use 'su myself' command first, then start
> xemacs. So, somehow the 'su' command makes it OK, but without
> that, the function are not visible from Xemacs (I want to use
> the functions in the compile command in xemacs).

Does .bashrc load when you log in? It should be loaded by bash
when it's reading (and executing) .bash_profile. There should be
something like:

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

--
 SwifT                     -    Key-ID CDBA2FDB
 LUG: http://www.lugwv.be  -    http://www.keyserver.net

 
 
 

bash function problem, unless su is used - please help!

Post by Peter T. Breue » Sun, 08 Jul 2001 00:10:07



> What is the difference between a terminal window shell environment and the one I get after
> an 'su' command (for the same user)?

What su command? Please be specific!

 "su" on its own will change your uid and nothing else, I believe.
 Read the manpage for its behaviour with other options.

Quote:> What configuration or setup files could be responsible for the lack of bash function inheritence to
> the xemacs sub-shell ?

Eh?

Peter

 
 
 

bash function problem, unless su is used - please help!

Post by Zsol » Sun, 08 Jul 2001 00:46:00




>> What is the difference between a terminal window shell environment and the one I get after
>> an 'su' command (for the same user)?

> What su command? Please be specific!

The comand, where I change to be a "different user", e.g.

$ su - zsolt

Where 'zsolt' is the user name.

Quote:>  "su" on its own will change your uid and nothing else, I believe.
>  Read the manpage for its behaviour with other options.

>> What configuration or setup files could be responsible for the lack of bash function inheritence
to
>> the xemacs sub-shell ?

> Eh?

OK. Here is what I do:
1. Login from kdm, window manager KDE, Launch a terminal window -> this gives me a shell, using
bash as that is set to be my default shell.

2. Right now, the bash functions that I defined in my .bashrc file are working from this shell, e.g.
if I issue the command "makes" - it calls my bashrc function makes() which will do some preparations
before calling the normal make command. However, if I start up xemacs from this terminal window or
from the KDE menu, then inside xemacs, there is a 'compile command', i.e. a command which will be
issued when you hit the 'compile' menu button - this invokes a shell to execute the given command.
By default it is set to be 'make -k'. I have changed that to be 'makes -k', to invoke the bash
function that I wrote (called makes) which does some additional stuff , e.g. changing directories.
However, when I invoke the compile command in xemacs, it gives an error message, that it does
not recognise the command 'makes'. So appearantly, the shell started by xemacs does not have the
definition from my bashrc.

3. Now, (my username is 'zsolt' as I logged in during step 3), I issue a pointless user name change
command, to switch to user 'zsolt' using 'su':


This should make no change whatsoever, as I was 'zsolt' user before and now I'm again 'zsolt' user.
However, if I startup xemacs from this shell, then press 'compile' it find the 'makes' command and
works OK.

Before I upgraded to Mandrake 8.0, I used Mandrake 7.2. With that system, my bash function worked
OK directly from xemacs. Some default configuration must have changed for the 8.0 release, which
resulted in this problem I have now. However, the 'su' command reverses that change for that shell.
But it is very cumbersome to use an extra 'su' each time, so I'd like to figure out how to change
the settings that I get this function working directly as it was before.

Thanks for your patience!

Zsolt

 
 
 

bash function problem, unless su is used - please help!

Post by Zsol » Sun, 08 Jul 2001 00:48:55




>> I have a weird problem with the bash shell (rpm:
>> bash-2.04-18mdk, default of Mandrake 8.0).
>> The shell functions, that I define in my .bashrc do not work
>> from an Xemacs window. They used to work in Mandrake 7.2, and
>> they still work if I use 'su myself' command first, then start
>> xemacs. So, somehow the 'su' command makes it OK, but without
>> that, the function are not visible from Xemacs (I want to use
>> the functions in the compile command in xemacs).

> Does .bashrc load when you log in? It should be loaded by bash
> when it's reading (and executing) .bash_profile. There should be
> something like:

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

Yes it is loaded, my function works if I call it from the shell (terminal window) directly. It does
not work when xemacs executes the 'compile' command - presumably it starts up a shell to execute it
and that shell does not execute my .bashrc for some reason.

Zsolt

 
 
 

bash function problem, unless su is used - please help!

Post by Peter T. Breue » Sun, 08 Jul 2001 01:26:48



> The comand, where I change to be a "different user", e.g.
> $ su - zsolt
> Where 'zsolt' is the user name.
>>  "su" on its own will change your uid and nothing else, I believe.
>>  Read the manpage for its behaviour with other options.

  OPTIONS
         -      make this a login shell

So obviously it executes the scripts specified for root's shell when
run as a login shell. If root's shell is bash, then that is:

       When bash is invoked as an interactive login shell, or  as
       a  non-interactive shell with the --login option, it first
       reads and executes commands from the file /etc/profile, if
       that  file  exists.  After reading that file, it looks for
       ~/.bash_profile, ~/.bash_login, and  ~/.profile,  in  that
       order,  and reads and executes commands from the first one
       that exists and is readable.

Note:

        The  current  environment is passed to the new shell.  The
        value of $PATH is reset to /bin:/usr/bin for normal users,
        or /sbin:/bin:/usr/sbin:/usr/bin for the super user ...

Quote:> 2. Right now, the bash functions that I defined in my .bashrc file are working from this shell, e.g.
> if I issue the command "makes" - it calls my bashrc function makes() which will do some preparations
> before calling the normal make command. However, if I start up xemacs from this terminal window or
> from the KDE menu, then inside xemacs, there is a 'compile command', i.e. a command which will be
> issued when you hit the 'compile' menu button - this invokes a shell to execute the given command.
> By default it is set to be 'make -k'. I have changed that to be 'makes -k', to invoke the bash
> function that I wrote (called makes) which does some additional stuff , e.g. changing directories.
> However, when I invoke the compile command in xemacs, it gives an error message, that it does
> not recognise the command 'makes'. So appearantly, the shell started by xemacs does not have the
> definition from my bashrc.

Indeed not, since it is not a login shell. Read the manpage for bash
for the other types of shell invoocations. I believe you
have a noninteractive nonlogin shell there ...

       When bash is started non-interactively,  to  run  a  shell
       script, for example, it looks for the variable BASH_ENV in
       the environment, expands its value if  it  appears  there,
       and  uses the expanded value as the name of a file to read
       and execute.  Bash behaves as  if  the  following  command
       were executed:
              if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
       but  the  value of the PATH variable is not used to search
       for the file name.

So presumably you want to set BASH_ENV to your functions script
file before calling emacs.

Quote:> Before I upgraded to Mandrake 8.0, I used Mandrake 7.2. With that system, my bash function worked
> OK directly from xemacs. Some default configuration must have changed for the 8.0 release, which

Read manpage for your new shell. Apparently it has changed. I don't
guarantee that I am using the same bash as you (and I don't use bash
anyway). In my version (2.03) of bash, no functions are exported
automatically to subshells, interactive or not. Obviously login
shells get the function defs anew.

Peter

 
 
 

1. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

Is there a proper fixed bash on any of the FTP sites out there?

I know there bash is on the usual sites but I don't know if they are
bugged or not :(

Regards,

Neil.

--


------------------------------------| Edinburgh, EH14 2DE, United Kingdom
**Domino: There`s nothing you can do when you`re the next in line: Domino**

2. XFree86 3.9.17 on RH6.1 compilation errors

3. Please help with simple Bash shell function

4. SLIP dead under pl14

5. can anyone see the error in this script please I am BASHing my head LOL

6. Netware for linux, where to download client ?

7. Please help, Windowmaker works only if csh is used, but not bash

8. Help: batch renaming files - stripping bogus extensions

9. Using su in bash scripts

10. using 'su' in bash shell?

11. Help: Problem with su(C) -- Please read!!

12. Why Wont X Run Unless I am Root?

13. Help: Problem with su(C) -- Please read!!