1835429 Members
3913 Online
110078 Solutions
New Discussion

alias command

 
SOLVED
Go to solution
MikeL_4
Super Advisor

alias command

When using the alias command for setting in .profile, is there a way to display the command thats going to be executed instead of executing it right away ?
8 REPLIES 8
Geoff Wild
Honored Contributor

Re: alias command

Not too sure if I know what you want - but if you just enter:

alias

it will tell you all the aliases configured...

Example:

# alias
autoload='typeset -fu'
command='command '
date=/bin/date
functions='typeset -f'
history='fc -l'
integer='typeset -i'
local=typeset
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='kill -STOP $$'
type='whence -v'



Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
c_51
Trusted Contributor

Re: alias command

and alias aliasName will just give the alias for just that alias.

and typeset -f will list the shell functions
MikeL_4
Super Advisor

Re: alias command


If I had an alias defined: command='ls -al /user ' When I enter the alias, command
don't execute the ls -al /user but rather display the line so I could modify it if needed to say: ls -al /tmp
Geoff Wild
Honored Contributor

Re: alias command

Then what you really want is an alias like this:

alias cmd="ls -al"

then

cmd /usr
cmd /user

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Muthukumar_5
Honored Contributor
Solution

Re: alias command

I got to know your requirement.

Try as,
$ alias test='echo "ls -l /user going to be executed"; echo "want to change (Y/N)"; read opt; if [[ $opt = "Y" || $opt = "y" ]]; then echo "Enter directory"; read dir; fi; ls -l $dir'

Execution of test will be as,

$ test
ls -l /user going to be executed
want to change (Y/N)
Y
Enter directory
.

It will display all files / directory there.
alias command can be used as shell script there.

HTH.
Easy to suggest when don't know about the problem!
Rodney Hills
Honored Contributor

Re: alias command

The "whence" command under ksh will display where a command is located or for an alias it will display the alias mapping.

HTH

-- Rod Hills
There be dragons...
Bill Hassell
Honored Contributor

Re: alias command

To amplify the whence command a bit, use whence -v or the built-in alias: type I have long abandoned which, whereis and alias to figure out what will happen when you type a particular command to the shell. Only type will give you correct information. For example, run which and whereis on these commands:

# which if for stop whence type
# whereis if for stop whence type

You'll see that if, for and stop are not found at all, and that type is /usr/bin/type. But none of those reports are correct at all. That is not what the shell will do. Now do this:

# type if for stop whence type
if is a keyword.
for is a keyword.
stop is an exported alias for kill -STOP
whence is a shell builtin.
type is an exported alias for whence -v

whence and type will tell you what the shell will do. "whereis type" might lead you to believe that /usr/bin/type will be run but that's incorrect. Instead, the shell will run the command whence -v and whence is a shell built-in.

So always use type to see what the shell will do. This is EXTREMELY important if you have the current working directory in $PATH (a very bad idea). If :. or :.: are in your $PATH, someone can put a script called su in some directory and get you to run it by mistake. type will tell where your su will be found by the current shell and environment.


Bill Hassell, sysadmin
MikeL_4
Super Advisor

Re: alias command

Thanks