[sf-lug] regular expression question
Sean
sean.channel at pacbell.net
Fri Jun 8 14:04:42 PDT 2012
You do need a function to process positional arguments in bash, as you have
found out like me the hard way.
bash evaluates the meaning of $1 and other variables at the time the alias is
defined, not when called later. Arguments you pass to an alias are simply
appended to the command, so
w3mtest gasoline
turns into:
w3m -dump -T text/html 'https://encrypted.google.com/search?q=' gasoline
..which yields only the aforementioned one-line and google search page. Defining
this as a function worked fine;
w3mtest()
{
w3m -dump -T text/html https://encrypted.google.com/search?q="$*"
}
HTH.
_S
On 06/08/2012 01:17 PM, James Sundquist wrote:
> So, I wrote some aliases that rely on user input that work just fine.
> alias h='history | grep $1"
>
> I tried doing the same thing for conducting quick google searches with the w3m
> pager, which can be used to browse text/html on the internet and is included on
> Ubuntu Server.
>
> $ w3m -dump -T text/html https://encrypted.google.com/search?q=news
>
> This will output the results of searching the term "news" on google's search
> to the display. Works like a charm
>
> alias w3mtest='w3m -dump -T text/html https://encrypted.google.com/search?q="$1"'
>
> I add this alias to bashrc and execute it with the argument "news" and bash
> will not successfully interpret the input. It outputs the Google search page
> and an additional line reading 'w3m: Can't load news'
>
> I've written this as a function and it works perfectly. What is stopping this
> from working as an alias? I'd love to get a fresh perspective. I've gotten
> this concept to work in elinks by creating a bookmark for google search (g) and
> simply adding my search terms to the end of it.
>
>
> _______________________________________________
> sf-lug mailing list
> sf-lug at linuxmafia.com
> http://linuxmafia.com/mailman/listinfo/sf-lug
> Information about SF-LUG is at http://www.sf-lug.org/
More information about the sf-lug
mailing list