Parameter expansion?

Booting, installing, newbie
Post Reply
Message
Author
RobbH
Posts: 13
Joined: Sat 13 Jan 2007, 19:37
Location: USA

Parameter expansion?

#1 Post by RobbH »

I've been through my "Linux for Totally Hopeless Idiots" book, and I've searched online guides. But I can't find the answer to this simple question.

I've got a sequence of commands I'd like to use frequently, something like this:

Code: Select all

grep -i searchstring list.txt > grepout.txt && geany grepout.txt
The searchstring will change, but everything else remains the same. What I'd like to do is create an alias or a script. I'd like to call the alias/script by name, adding the searchstring as an argument. Like this:

Code: Select all

finditnow searchstring
How do I do this? I'm sure the answer must be staring me in the face. This is the sort of thing I used to do all the time in DOS and 4DOS, and I still use some of those 4DOS aliases, somehting like this:

Code: Select all

grep -i %1 list.txt > grepout.txt && geany grepout.txt
The answer has so far eluded me. Anyone willing to rescue me?

User avatar
Gn2
Posts: 943
Joined: Mon 16 Oct 2006, 05:33
Location: virtual - Veni vidi, nihil est adpulerit

#2 Post by Gn2 »

Make Google your ally Esp for Generic Linux queries !

Seems like what you want is to PIPE (redirect) the search string results to another tool.

You could use the pipe (|) symbol, <-(upper-case key over " \") the cat command or redirection symbol {>)

http://intro.mainstreamlinux.com/sect_05_01.html
To use aliased commands, place in (dot) .bashrc file (under user or root home folder)

To use aliased command immediately without re-booting,

Code: Select all

source ~/.bashrc
See also use of command separators, else the last performed terminates the parsed string sequence, exits.

Please see also use of interactive shell (consult on-line)
Google for downloadable BASH MANUAL
For advanced search, parsing, srting manipulations &/or redirecting > see GAWK < & > SED manuals

MORE LINUX

HTH

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#3 Post by MU »

mygrep

Code: Select all

#!/bin/bash

# usage: mygrep searchstring

grep -i "$@" list.txt > /tmp/grepout.txt && geany /tmp/grepout.txt


Mark

RobbH
Posts: 13
Joined: Sat 13 Jan 2007, 19:37
Location: USA

#4 Post by RobbH »

MU wrote:
grep -i "$@" list.txt > /tmp/grepout.txt && geany /tmp/grepout.txt
Thank you, Mark! Exactly what I was looking for.

RobbH
Posts: 13
Joined: Sat 13 Jan 2007, 19:37
Location: USA

#5 Post by RobbH »

Incidentally, I appreciate Mark's willingness to help, even though my question was apparently off-topic. I did spend some time searching for the answer, both in printed reference materials and online, before asking my question here. I admit that it did not occur to me that the question might be off-topic in the newbies' forum, but I now see that statement in another thread:

http://www.murga-linux.com/puppy/viewto ... 3909#93909

Like many newbies, there are times when I do not know enough about a subject to ask a question intelligently, and sometimes I can't formulate an effective search string, either. In this case, even now that I have Mark's very helpful answer, I haven't been able to find any additional useful information on the subject online. I do find many copies of essentially the same text on shell parameter expansion, which reads like a man page and at this point is not comprehensible to me.

So, where should newbies go with basic, generic questions about Linux, not specific to Puppy, when we have exhausted our ability to search out an answer?

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#6 Post by Pizzasgood »

I'd say the "Users" topic. That's what I do, anyways.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
Gn2
Posts: 943
Joined: Mon 16 Oct 2006, 05:33
Location: virtual - Veni vidi, nihil est adpulerit

#7 Post by Gn2 »

when we have exhausted our ability to search out an answer?
That has been addressed many times - GOOGLE
Now I know how that sounds -in text & Esp when no facial clues are evident - but really - isn't it more of:

Examples abound - In these forum headers, are many URL's to resources.
A very comprehensive example was supplied in above -
The WEB is so full - how can anyone run out of ideas ?
(If anything, the choices are overwhelming)

Yes I fully realize & can share learning pains to what may seem (at first glance) like @!!## Greek Esp if a new_to_linux user -
But please consider, which will be Far More Reliable

Isn't it more a matter - of users patience & willingness that determines results ?
We have all been there - NOBODY is a "so-called expert" !
Only different temporary experience levels in any given time frame.

It was best expressed:
~ It's not that I'm so smart, it's just that I stay with problems longer.
~ Problems cannot be solved by the same level of understanding that created them
= It's not what you look at that matters, it's what you see.
~ Albert Einstein
When REALLY exasperated - I find some :wink: comfort in
I think the next best thing to solving a problem is finding some humor in it.
Frank A. Clark

Post Reply