how can I export an alias and use it in any shell that I want to switch to like bash, ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how can I export an alias and use it in any shell that I want to switch to like bash, ksh
# 1  
Old 03-18-2011
how can I export an alias and use it in any shell that I want to switch to like bash, ksh

None of the aliases that I set are available if I switch to a different shell.

How can I export aliases and make them available in any shell that I switch to like ksh or bash ?

I tried these

Code:
 
$>alias godata='cd /home/kc/app/data'
$>alias -x godata='cd /home/kc/app/data'
$>alias | grep godata  # its available in current-shell
godata='cd /home/kc/app/data'
 
$>ksh                  # Here I am switching to a new ksh shell
 
$>alias | grep godata  # How can I export aliases so that I can access them here.
<none>

# 2  
Old 03-18-2011
AFAIK, each shell has its own shell-wide configuration file, e.g. on bash its .bashrc, .bash_profile, /etc/bashrc, etc.

To keep your alias set across different shells, you need to export it on a lower level -- /etc/profile should work for system wide config (all users). If you want to set the alias only for one user, define it in ${HOME}/.profile, which gets read when a new login shell is started.

Quote:
$ ksh --help
Usage: ksh [ options ] [arg ...]
OPTIONS

-l Invoke the shell as a login shell; /etc/profile and $HOME/.profile, if they exist, are read before the first command.
# 3  
Old 03-20-2011
Thanks mirni, it appears for my scenario executing same alias file(. ~/.setalias)
in .bashrc and .kshrc is the best solution.

I will take it from this that one can't export alias definition like PATH or EDITOR, when same user switches into other shells(bash/ksh/csh/!..).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Invoking a bash shell with an export var

Hello all, How can I invoke the bash shell (via command line) to execute another command by setting an exported environmental variable on the fly (as this env var would be used by the command -another script, the bash would execute). This needs to be done in one single line as the same would... (4 Replies)
Discussion started by: Praveen_218
4 Replies

2. Shell Programming and Scripting

How to run ksh script in bash shell?

Hi All, I have few bash shell scripts which depends on one Ksh shell script. When i run bash shell scripts, it shows error as bad interpretor : ksh no such bad file or directory. When i tried to install ksh shell, it is not downloading too. If I remove !/bin/ksh command in starting line of the... (14 Replies)
Discussion started by: Karthik03
14 Replies

3. Shell Programming and Scripting

alias is ksh

Hello, I am trying to create alias in ksh. alias m=main.ksh It's working just fine but when I log out from my session and relogin the alias is gone. How can i create a permanent alias? Thanks... (1 Reply)
Discussion started by: LiorAmitai
1 Replies

4. UNIX for Dummies Questions & Answers

alias in ksh

Hi all, I want to create my own set of alias, possibly place them on a script that I can run manually as a script. I've placed the sequence of alias commands in a file then I logoff and login and run the script manually. That does not seem to work, can anyone please advise how to get this work... (2 Replies)
Discussion started by: newbie_01
2 Replies

5. Shell Programming and Scripting

export not working in Bash shell

Hi Friends, I am presently migrating shell scripts writter in KSH to SH.I am stuck at this place and i am not able to find a work around:- Let the script name is x.sh Below are some of the codes in it... export abc=hello export abc=hi export abc=how When i am trying to compile the script ... (6 Replies)
Discussion started by: amit.behera
6 Replies

6. UNIX for Dummies Questions & Answers

alias in bash shell for CTRL + l

Is it possible to create an alias wherein it will use a keystroke. Like to clear the screen in bash i have to use CTRL + l. I want to make an alias 'c' out of this. Thanks. (6 Replies)
Discussion started by: or_knob
6 Replies

7. UNIX for Dummies Questions & Answers

Change the default shell from bash to ksh

Currently my default shell is bash.How can i change itto ksh... (2 Replies)
Discussion started by: dr46014
2 Replies

8. Shell Programming and Scripting

Export Arrays in ksh

Hello everybody! Why I can export arrays in ksh? I trie this for exemplo: In parent script array=a array=b array=c export array When I see the variable array in child script there are only first index. For exemplo in child script +echo ${array} a (3 Replies)
Discussion started by: ricardo.ludwig
3 Replies

9. UNIX for Dummies Questions & Answers

ksh export

Hi, What is the difference between the following two usage of export? export VARIABLE_NAME;VARIABLE_NAME=value and export VARIABLE_NAME=value Cheers, Vish (1 Reply)
Discussion started by: z_vishnu
1 Replies

10. UNIX for Dummies Questions & Answers

switch from csh to ksh

My UNIX SA requires that we start in CSH. I like to use KSH because most of my experience is in that shell. I added ksh to the end of my .login script which does take me into KSH but I would like to automatically execute my .profile to setup my aliases. I cannot use a .shell file because I... (1 Reply)
Discussion started by: veeracer
1 Replies
Login or Register to Ask a Question