LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 01-28-2003, 11:29 AM   #1
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
.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.
 
Old 01-28-2003, 02:39 PM   #2
leed_25
Member
 
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

Rep: Reputation: 17
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.
 
Old 01-28-2003, 07:11 PM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,305

Rep: Reputation: 66
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'
 
Old 01-29-2003, 02:45 AM   #4
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Original Poster
Rep: Reputation: 57
Thanks whansard!
 
Old 01-29-2003, 12:19 PM   #5
leed_25
Member
 
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

Rep: Reputation: 17
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.
 
Old 01-30-2003, 01:15 AM   #6
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,305

Rep: Reputation: 66
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.
 
Old 01-30-2003, 04:52 PM   #7
leed_25
Member
 
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

Rep: Reputation: 17
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.
 
Old 01-30-2003, 05:54 PM   #8
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Original Poster
Rep: Reputation: 57
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?
 
Old 01-30-2003, 06:42 PM   #9
nxny
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: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Eterm doesn't import aliases from bashrc oldmanofthesea Linux - General 1 05-16-2005 07:17 AM
bashrc Aliases don't work soren625 Linux - Newbie 10 01-27-2005 08:59 AM
making aliases - no bashrc file disorderly Linux - Newbie 9 09-27-2004 04:57 PM
adding aliases, refreshing .bashrc NonSumPisces Linux - Newbie 8 06-25-2004 11:39 PM
aliases in .bashrc file davalos Linux - Newbie 7 08-21-2003 01:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration