|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
is there a way to defien in an 'alias' where the command-line arguments are used??
as an example I will use a csh alias: alias dir 'ls -alrtF \!* | more' |
|
#2
|
|||
|
|||
|
No. In ksh, an alias only renames a command. Use a function instead.
dir() { ls -alrtF $* ; } |
|
#3
|
|||
|
|||
|
I am able to do this in Solaris 5.8. If I understood the problem rightly then
alias dir='ls -l' then doing *dir* does the same function as *ls -l* Regards
__________________
Regards JK |
|
#4
|
|||
|
|||
|
I missed out to add these also
# alias dir='ls -l $*' # dir demo.c -rw-r--r-- 1 root other 1279 Jan 17 2003 demo.c # dir demo.c fchmod.c -rw-r--r-- 1 root other 1279 Jan 17 2003 demo.c -rw-r--r-- 1 root other 3702 Jan 28 2003 fchmod.c # See we can give the command line arugments also using alias |
|
#5
|
|||
|
|||
|
Quote:
But only if the rename is enough, which is rarely the case. Notice that the OP really wanted the output of ls piped though more. So a more complete function would have been: dir() { ls -alrtF $* | more ; } Try that with an alias... ![]() |
|
#6
|
|||
|
|||
|
Dear,
It also work with more try this alias dir='ls -l $* | more' $ dir It has the same behaviour. I tried this in Solaris 5.8 ![]() |
|
#7
|
|||
|
|||
|
I just tried on solaris 5.8 using ksh and it failed. What shell are you using?
Try this: set one two three alias xyz='echo $* ; echo next line ; echo ' xyz four five xyz six seven That $* in the alias will expand to "one two three". The arguments that you pass to the alias get tacked on to the end of the command line. If you issue your alias: dir="ls -l $* | more' and then do dir /etc/passwd you will indeed pass an argument to the alias and the result will basicly boil down to: more /etc/passwd the "ls -l one two three" may succeed if you have those files, but more will ignore the output of ls in this case. Or you may see errors about one two and three not existing. While you may chuckle with delight over the functionality of this wonderful alias, try to understand that it's not what the OP was looking for. He wanted the $* to be replaced with the arguments that he passed to the alias. In ksh, that will require a function. |
|
#8
|
|||
|
|||
|
Yeah you are right
Quote:
Cheers JK |
|
#9
|
|||
|
|||
|
alias
hi ther,
i just tried this syntax u hav posted: dir() { ls -l ; } -and it works. but how come after launching another session, the defined alias is gone/missing. so it cannot use by other sessions. how can i define this so other terminals can use also. appreciate for any feedback. Thanks. |
|
#10
|
|||
|
|||
|
If you want it to be for every seesion you need to put the function definition (or alias if you wish to use that instead) in the .profile of the user.
|
|
#11
|
|||
|
|||
|
thanks for the advice, however, i just did, but stil not working. after adding to .profile, do i need to restart any service? i just insert the command:
# dir() { ls -l ; } -- thats it. anything i missed out. pls help. Thanks a lot for your time. |
|
#12
|
||||
|
||||
|
That should work - you WILL need to source the .profile (either by logging off and on again or by . .profile). This is, of course, assuming your shell is one that uses .profile (ksh, etc.). If not, then you'd need to put the function defintion in the correct file: .cshrc (I think, for the C shell).
In any event, doing that with an alias would be better! |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > ksh alias arguments |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|