How to set a global alias in UNIX Solaris?


 
Thread Tools Search this Thread
Operating Systems Solaris How to set a global alias in UNIX Solaris?
# 1  
Old 04-11-2013
Sun How to set a global alias in UNIX Solaris?

Defined a user alias in unix. Not able to use that alias in a ksh scritp. I dont want to change/source in the script to set the value. Need to set the user alias as a gloabal alias to use it in a new ksh shell window. Can you please help on this?
# 2  
Old 04-11-2013
Code:
# set ENV ex. in the $HOME/.profile
ENV=$HOME/.kshrc
export ENV

Then make $HOME/.kshrc file which include all your commands which you like to execute always when you start new ksh process.

Example $HOME/.kshrc:
Code:
# global function
hellow()
{
  echo "Hello world!"
}

alias dir='ls -al'
date

Then start new ksh process or run script which use ksh. You will see always date output.
# 3  
Old 04-12-2013
Quote:
Originally Posted by rbalaj16
Defined a user alias in unix. Not able to use that alias in a ksh scritp.
Aliases mostly work interactively, not inside scripts.

If you could rewrite it as a function -- not hard at all -- that could work in scripts.
# 4  
Old 04-12-2013
Quote:
Originally Posted by Corona688
Aliases mostly work interactively, not inside scripts.
This is true (by default) with bash, but the OP is using ksh. The latter makes no restrictions with aliases in scripts.

---------- Post updated at 22:09 ---------- Previous update was at 22:03 ----------

Quote:
Originally Posted by rbalaj16
Need to set the user alias as a gloabal alias to use it in a new ksh shell window.
You cannot anymore export aliases with the current ksh releases. Aliases must be defined either in your shell scripts or in files sourced by your scripts.
One way to do it without modifying existing scripts would be to use the ENV ksh variable and set it to point to a script defining your aliases.

That written, I concur with Corona688 functions are better than aliases and should be used instead.

If you decide to use functions, you can use the FPATH variable to point to a directory where your functions are defined (one file per function).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to set Global variable outside while loop

Below is my code: count=0 if ... ... else ... find * -prune -type d | sort -r -n | while read d; do count=1 if ; then echo "Count1:$count" ... ... break 2; fi ... done ... fi echo "Count2:$count" (9 Replies)
Discussion started by: mohtashims
9 Replies

2. UNIX for Dummies Questions & Answers

Can't find where alias is set

I have an alias set on linux: progs -> /home/user01/prog1.pl the location of prog is changes to /home/user01/new/prog1.pl so I need to modify alias, except I can not find where it is set. It is not in .bashrc or .profile, it is visible by "alias" command. Sorry if it is trivial. (4 Replies)
Discussion started by: analyst
4 Replies

3. UNIX for Dummies Questions & Answers

set global rm command

Hi, My team does not have root access however many a times my members logon to the unix server and fire the rm command mistakenly on wrong folder and later realise that they have made a mess. The rm -i option prompts for a confirmation before actually deleting the files/folders. I want to... (5 Replies)
Discussion started by: shifahim
5 Replies

4. Solaris

How to identify a global or non-global Solaris server?

Hi, I have Solaris zone configured with Solaris 9 and 10. In Solaris 10(non global), I use the command “zonename” to get whether it is global or non-global server. For Solaris 9, what command I can use to get whether it is global or non-global server. Regards, Kalai :confused: (25 Replies)
Discussion started by: kalpeer
25 Replies

5. UNIX for Dummies Questions & Answers

Alias in solaris

Hi, i need to create a alias in my solaris 10 , i have edited ~/.profile and added like alias c='clear'and exit the terminal and open again and checked to see working or not but it's still not working (9 Replies)
Discussion started by: malickhat
9 Replies

6. Shell Programming and Scripting

Global alias does not work in shell script

Hi Linux Set up - alias ls='ls -l' Then run script #! /bin/ksh sub() { ls } sub Is there any way to get it working. I don't want to define alias inside of the program Thank you (2 Replies)
Discussion started by: zam
2 Replies

7. Shell Programming and Scripting

global variable not being set

In ksh I thought a global variable was any variable in a script or function that did not have the typeset command. I have a global in my calling script which I increment in a function, but the value does not change in the calling script. Here is the code: function f_open_log { typeset -r... (5 Replies)
Discussion started by: robotball
5 Replies

8. Shell Programming and Scripting

How to set alias and ps1 in a script

I am sure this is a newbie question, but I have searched everywhere and cannot find an answer. My situation is that due security constraints, I cannot modify my .profile file. I have a set of fairly common things that would normally go in the .profile, like setting up alias assignments and... (2 Replies)
Discussion started by: SpringRubber
2 Replies

9. AIX

global alias

how do we set global aliases in aix, which will work across different shells? TIA (3 Replies)
Discussion started by: dbins01
3 Replies
Login or Register to Ask a Question