Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-28-2003, 11:29 AM
|
#1
|
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503
Rep:
|
.bashrc aliases
I have a question when creating an alias.
Say I want an alias command that sees if I have a certain package installed. In the .bashrc file I would put:
alias rpmfind='rpm -qa | grep'
Okay cool. Now say I want to pipe the output to the more command. This is where I get lost in the syntax. Would it be:
alias rpmfind='rpm -qa | grep' '| more'
Probably not! My question is how do I represent the variable that is being passed to the command.
rpmfind='rpm -qa | grep (HowDoIRepresentVariableHere) | more'
I'm sure this is a simple question. Thanks.
|
|
|
01-28-2003, 02:39 PM
|
#2
|
Member
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102
Rep:
|
well, here's one way. I rewrote your alias a little bit to grep all of the php files in and below the current directory, but you'll get the idea, i hope
Code:
alias localfind=_localfind
function _localfind
{
find . -name "*.php" -print | xargs grep $1 | more
}
did this help?
click here
Last edited by leed_25; 01-28-2003 at 02:57 PM.
|
|
|
01-28-2003, 07:11 PM
|
#3
|
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306
Rep:
|
when you want to pass variables to the alias,
use $1 and up for each variable you pass on the line.
such as
alias delete3files = 'rm $1 $2 $3'
then you can
delete3files thisone thatone otherone
or for more commands in one alias
alias c= 'cd .. ; ls --color -s -a'
|
|
|
01-29-2003, 02:45 AM
|
#4
|
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503
Original Poster
Rep:
|
Thanks whansard!
|
|
|
01-29-2003, 12:19 PM
|
#5
|
Member
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102
Rep:
|
Ahem. In the online documentation for Bash at the
gnu.org site --the horse's mouth, if you will,
see here
you will find this statement:
Quote:
There is no mechanism for using arguments
in the replacement text, as in csh. If arguments
are needed, a shell function should be used (see
section 3.3 Shell Functions).
|
did this help? please click
here
Last edited by leed_25; 01-29-2003 at 12:22 PM.
|
|
|
01-30-2003, 01:15 AM
|
#6
|
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,306
Rep:
|
I think i was mixed up and just thinking about bash
scripts, and got aliases mixed up.
yea, the alias just substitutes the command.
bash carries the variables.
I looked at that 3 times today, and just thought you
were being snooty, but i was just mixed up. It took
me 3 times to realize it.
|
|
|
01-30-2003, 04:52 PM
|
#7
|
Member
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102
Rep:
|
Whansard, I certainly was not trying to be snooty.
I noticed an error in your post so I thought that
it would be a better thing to offer a correction
with a cited reference than it would be to let
that error mislead others.
I have been programming for a quite some time now
and I've made my fair share of mistakes --some of
them were real whoppers, too-- so, believe me, I
know how it happens.
|
|
|
01-30-2003, 05:54 PM
|
#8
|
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503
Original Poster
Rep:
|
Thanks everyone. Hey leed_25 I want to get a good book on linux programming. I'm not a newbie programmer (It was my concentration in college) but I would like a book that is pretty easy to understand. God knows I had some programming books in college that were so confusing I just used them as kindling for the fire. Any suggestions?
|
|
|
01-30-2003, 06:42 PM
|
#9
|
Member
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771
Rep:
|
Take a look at RUTE .
You can read it online with a gzip compliant browser ( Mozilla, Netscape 7)
To me at doesnt get any better than this, so I bought it in print from Amazon.
|
|
|
All times are GMT -5. The time now is 07:27 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|