1829559 Members
2017 Online
109992 Solutions
New Discussion

Alias question

 
SOLVED
Go to solution
UniRock
Regular Advisor

Alias question

Hi All,

We can set alias by:
# alias ls='ls -al'

But, what if I want to set an alias for:
"vgdisplay -v" to "abc"

So, I can run:
# abc vg01
and get results for "vgdisplay -v vg01".

Is that possible?
Thanks..
4 REPLIES 4
SoorajCleris
Honored Contributor

Re: Alias question

y not ???


# alias abc='vgdisplay -v'
[rx260-13]/
# abc vg00
--- Volume groups ---
VG Name /dev/vg00
VG Write Access read/write
VG Status available
Max LV 255
Cur LV 8
Open LV 8
Max PV 16
Cur PV 1
Act PV 1
Max PE per PV 4356
VGDA 2
PE Size (Mbytes) 32
Total PE 4346
Alloc PE


Regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
R.K. #
Honored Contributor

Re: Alias question

Thanks Sooraj,

I guess I have put the question in a wrong way. Let me give an example, how can I put alias for 'vgdisplay -v vg01' for 'vgdisplay -v vg02', so that when I execute the command:
# vgdisplay -v vg01
We get the result for 'vgdisplay -v vg02'....something like:

# alias 'vgdisplay -v vg01'='vgdisplay -v vg02' <<<< well this do not work :-(

So, I am looking on how to use multiple words on both sides of '=' while using alias.

May be it is more clear this time :-)
Don't fix what ain't broke
Dennis Handly
Acclaimed Contributor

Re: Alias question

>how can I put alias for 'vgdisplay -v vg01' for 'vgdisplay -v vg02'

You can not. You should give up on aliases and use functions or scripts:

># vgdisplay -v vg01 # We get the result for 'vgdisplay -v vg02'

vgdisplay:
#!/usr/bin/ksh
if [ X"$1" = "X-v" -a X"$2" = Xvg01 ]; then
/usr/sbin/vgdisplay -v vg02
else
/usr/sbin/vgdisplay "$@"
fi
Laurent Menase
Honored Contributor
Solution

Re: Alias question

Hi,

in fact you need to use a function and not an alias
function vgdisplay {
if [ $# = 0 ]
then
/usr/sbin/vgdisplay
return $?
fi
set -A x -- "$@"
typeset -i xs=${#x[*]}-1
target="${x[xs]}"
if [ "${x[xs]}" = vg01 ]
then
x[xs]=vg00
fi
/usr/sbin/vgdisplay "${x[@]}"
return $?
}