bash question/help

bash question/help

Post by Nagabhushana T. Sindhushaya » Tue, 07 Nov 1995 04:00:00



Hi,

I have a question on using aliases in the bash shell environment.

I created a shell script with a list of aliases (each in the format
alias name=value) and ran the script, but none of the aliases took effect.
Then I tried typing those same alias commands on the prompt one by one,
and the alia worked.  

I think the problem may be that the script file is executed in its own
shell, and the effects are not propogated to the external world.  Is there
a way to
"export" the aliases defined in the shell script?

Please CC your responses to my email address.   Thanks in advance,

bhushan

--

phone: x3226

 
 
 

bash question/help

Post by David Bourgi » Thu, 09 Nov 1995 04:00:00



> Hi,

> I have a question on using aliases in the bash shell environment.

> I created a shell script with a list of aliases (each in the format
> alias name=value) and ran the script, but none of the aliases took effect.
> Then I tried typing those same alias commands on the prompt one by one,
> and the alia worked.

This is a UNIX FAQ and not a LINUX FAQ but here's the answer.

I use tcsh as shell but the info will be exactly the same for you.

To enforce to use a particular shell, just add at the top of your
text file the following line:
#!/usr/local/bin/tcsh

(For you this will be bash instead of tcsh)

Check out if your bash config file exists. It should be placed
at ~/.bashrc (with tcsh it's ~/.cshrc).

When you want to execute a shell command, just type:

UNIX> source shell_file_to_exec
(this is right with tcsh)

With bash, just make your shell_file_to_exec file as executable
with chmod command. Then type directly its name. Don't forget
at the top to put the #!... line.

Quote:> I think the problem may be that the script file is executed in its own
> shell, and the effects are not propogated to the external world.  Is there
> a way to
> "export" the aliases defined in the shell script?

Actually, an alias command should not be given with '='. It means
you should put in the file or on the command line:

UNIX> alias toto titi

Quote:> Please CC your responses to my email address.   Thanks in advance,

Each time I mail a send an answer it's simulatneously posted and
e-mailed. Sometimes the replying e-mail bounces that's why I prefer
to keep such a cross posting.

Hope it helps.

PS: Never forget that LINUX is UNIX like. Try to get a good book
of UNIX (in the closest library of the closest university, if possible).
Or post directly the help question in the right news group.
--
                                                David
  /mmm\        /mmm\        /mmm\
  (O o)        (O O)        (o o)
    U            U            u           /mmm\
  ||\  \\        / \\         .           (- -)
 oOOo__oOOo   _____oOOo  ___________  ______u_oOOo___
############  #########  ###########  ################
(BAD ANSWER)   (RETRY)   (ONCE MORE)  (Bored & Asleep)
+----------------------------------------------------+

|       UFR IMA (French University - Grenoble)       |
|I'm a netsurfer, and as such a citizen of the world!|

 
 
 

bash question/help

Post by ole » Wed, 15 Nov 1995 04:00:00



:Hi,
:I have a question on using aliases in the bash shell environment.
:I created a shell script with a list of aliases (each in the format
:alias name=value) and ran the script, but none of the aliases took effect.
:Then I tried typing those same alias commands on the prompt one by one,
:and the alia worked.  

When you start script you fork new process (sh), build new enviroment
in it, and sucsessfully exit from it and it's enviroment, because generally
you cannot pass enviroment "upward" (only "downward").
But your problem have solution:

". script"

. - the best sign I've seen in U*X

Oleg
=========================

VENI,VEDI,FTP
=========================

 
 
 

bash question/help

Post by Chet Ram » Thu, 16 Nov 1995 04:00:00


Quote:>> Aliases aren't available in a non-interactive environment (ie: shell script).

>Excuse me?  Since when?

It's right there in the bash manual page:

odin(2)$ grep -i 'aliases.*expanded.*interactive' bash.1
Aliases are not expanded when the shell is not interactive.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer


 
 
 

bash question/help

Post by Juergen Il » Fri, 17 Nov 1995 04:00:00



: :Hi,
: :I have a question on using aliases in the bash shell environment.
: :I created a shell script with a list of aliases (each in the format
: :alias name=value) and ran the script, but none of the aliases took effect.
: :Then I tried typing those same alias commands on the prompt one by one,
: :and the alia worked.  
:
: When you start script you fork new process (sh), build new enviroment
: in it, and sucsessfully exit from it and it's enviroment, because generally
: you cannot pass enviroment "upward" (only "downward").
: But your problem have solution:
:
: ". script"
:

If you want to have these aliases in every interactive bash you start,
it is good idea to append them to the file .bashrc in your homedirectory.
This file is sourced every time an interactive bash is started. Do not
write aliases in .profile or /etc/profile, otherwise they would take
effect only in your login-shell, not in subshells.

hope that helps,
        cia,

 
 
 

bash question/help

Post by M.Buchenried » Fri, 17 Nov 1995 04:00:00



>If you want to have these aliases in every interactive bash you start,
>it is good idea to append them to the file .bashrc in your homedirectory.
>This file is sourced every time an interactive bash is started. Do not
>write aliases in .profile or /etc/profile, otherwise they would take
>effect only in your login-shell, not in subshells.

But take care that you have /bin/bash in /etc/passwd as your login shell .
If it's /bin/sh (being linked to /bin/bash) the file .bashrc doesn't
get read .

Michael
--

**************************************************************************
* Our continuing mission: To seek out knowledge of C, to explore strange *
* UNIX commands and to boldly code where no one has manpage 4...         *

 
 
 

bash question/help

Post by John F Stur » Sat, 18 Nov 1995 04:00:00



amey) writes:

> >> Aliases aren't available in a non-interactive environment (ie: shell script).

> >Excuse me?  Since when?

> It's right there in the bash manual page:

> odin(2)$ grep -i 'aliases.*expanded.*interactive' bash.1
> Aliases are not expanded when the shell is not interactive.
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer



I'm sorry ... I owe you an apology.  You're quite right.  I just switched to
bash from ksh, and I wasn't aware of the difference.  (At least, I _think_
aliases are expanded from a script under ksh ...)

John Sturtz

 
 
 

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. ATI LT and LCD

3. Stupid BASH BASH EXPORT PS1 and path to X Question

4. How to configure a DNS-resolver

5. Bashing bash (Was Re: bash or user error with set -e and subshells)

6. Linux 2.4.18: short dd read from IDE cdrom

7. Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

8. Advfs I/O error [5] Tru64 version 4.0D

9. Bash Question - Please help

10. Bash/CGI - - HTML call to Bash script

11. difference in behaviour of bash-2.0 from bash-1.14.7

12. (patch for Bash) Bash with embedded Python

13. co-processes and bash (ksh does it, can bash?)