Search Members Help

» Welcome Guest
[ Log In :: Register ]

 

[ Track This Topic :: Email This Topic :: Print this topic ]

reply to topic new topic new poll
Topic: Unix Question< Next Oldest | Next Newest >
 Post Number: 1
demonk Search for posts by this member.
The other white meat
Avatar



Group: Members
Posts: 800
Joined: Aug. 2000
PostIcon Posted on: Jul. 16 2001,18:33  Skip to the next post in this topic. Ignore posts   QUOTE

Ok all you Unix Gurus, I have a question. In your .chsrc or .bashrc or .whatever file you can define aliases, so that I can type ll and realy get the ls -l command. Well, how would I define an alias so that if I did "ll -mycommand" I would get "ls -l -mycommand -secondcommand" or whatever. It's the first part, the defining what will be aliased that I'm having problems with. It will only see the first part of the command, and none of the command line options, and will just spit out an error when the command is run. Hope that wasn't too cryptic.
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 2
damien_s_lucifer Search for posts by this member.
Emperor of Detnet
Avatar



Group: Members
Posts: 33
Joined: Jan. 1970
PostIcon Posted on: Jul. 16 2001,19:25 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

csh and similar :
alias ll ls -l ũ Ū ū Ŭ

continue the $n series if you think you'll ever want to pass more than 4 arguments.

bash and similar :
alias ll='ls -l $@'

this passes ALL arguments; no need to add anything more.

This message has been edited by damien_s_lucifer on July 17, 2001 at 02:32 PM

Offline
Top of Page Profile Contact Info WEB 
 Post Number: 3
demonk Search for posts by this member.
The other white meat
Avatar



Group: Members
Posts: 800
Joined: Aug. 2000
PostIcon Posted on: Jul. 16 2001,19:29 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

No, I want to do this

alias ll -ũ ls -l -a ũ

or something to that extent. Let me give you a real world example:

alias (ael def) (ael def -lm1)

please ignore the (), I put them there just to show you want is the first part and what is the second part. See if someon types ael def, I want to automatically at that -lm1. But, if someone types ael, I don't want the -lm1 added since it wouldn't work with the def part.

Offline
Top of Page Profile Contact Info WEB 
 Post Number: 4
damien_s_lucifer Search for posts by this member.
Emperor of Detnet
Avatar



Group: Members
Posts: 33
Joined: Jan. 1970
PostIcon Posted on: Jul. 16 2001,19:39 Skip to the previous post in this topic.  Ignore posts   QUOTE

ah. Well, you won't be able to do that with the alias command; you'll have to write a shell script or use Perl.

What you're essentially saying is

"If there's no argument, do one thing, but if there IS an argument, do something else."

In Perl :

#!/usr/bin/perl

if ($ARGV[1])
{
`ael $ARGV[1] -lm1`;
}
else
{
`ael`;
}


You can do the same thing in shell script, but I'm too lazy to dig thru my reference manual


edit : typos.

This message has been edited by damien_s_lucifer on July 17, 2001 at 02:40 PM

Offline
Top of Page Profile Contact Info WEB 
3 replies since Jul. 16 2001,18:33 < Next Oldest | Next Newest >

[ Track This Topic :: Email This Topic :: Print this topic ]


 
reply to topic new topic new poll

» Quick Reply Unix Question
iB Code Buttons
You are posting as:

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code