Re: Why 'alias' cannot run by shell script?
From: Dana French (dfrench_at_mtxia.com)
Date: 09/08/04
- Previous message: William Park: "Re: rename files"
- In reply to: wilson: "Why 'alias' cannot run by shell script?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 8 Sep 2004 12:41:06 -0700
wilsonidv@hotmail.com (wilson) wrote in message news:<5dbdd79a.0409080202.6c7f4b5c@posting.google.com>...
> Hello all,
>
> I wrote a shell script below:
>
> #!/bin/bash
> ### MyScript ###
>
> alias m='mount /mnt/floppy'
> alias r='reboot'
>
> After editing, I added the 'x' permission and it can be executed
> correctly after I input ./MyScript.sh
> But why the script was of no effect? I input 'm' or 'r', the error
> message 'command not found' occurred.
>
> Please correct me where I miswrote, thanks.
When you run a script it is normally invoked in a subshell, meaning
the variables, functions, shell options, and ALIASES you define in the
script are not seen by the parent shell ( the shell from which you
executed the script ). You can execute your script as a "dot" script
to cause it to be executed in the current shell as follows:
. ./MyScript.sh
Thats dot-space-dot-slash-MyScript.sh
However it is more likely you are attempting to set these aliases in
your login environment so that they are always available. If so, then
you will need to create a .bashrc file, insert your aliases, shell
variables, shell options, functions, and anything else you want to be
defined every time you start a new shell. Then in your .bash_profile
define the following environment variable:
BASH_ENV="${HOME}/.bashrc"
export BASH_ENV
Then logout and back in again. Now your aliases should be defined in
your login shell as well as all subshells.
--------------------------------------------------------
Dana French dfrench@mtxia.com
Mt Xia Technical Consulting Group http://www.mtxia.com
100% Spam Free Email http://www.ridmail.com
MicroEmacs http://uemacs.tripod.com
Korn Shell Web http://dfrench.tripod.com/kshweb.html
- Previous message: William Park: "Re: rename files"
- In reply to: wilson: "Why 'alias' cannot run by shell script?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|