Help on creating and saving an alias | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Help on creating and saving an alias

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2013
mar85 mar85 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 22 August 2013, 10:09 PM EDT
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
Help on creating and saving an alias

Hello,
I want to create an alias for this command:

Code:
grep -i "<keyword_to_search>" <path_to_search>

Here's the alias I intended to make:

Code:
alias k 'set ARGS1 =(\!1); set ARGS2 =(\!2); grep -i "$ARGS1" ARGS2'

So that next time, for example, if I want to search the keyword "Help" in the path "./test/*", I type in the shell:

Code:
k Help ./test/*

I've try the above alias, but has error: 1: Event not found

Do you guys have any idea on what causing the error?
Thanks in advance
Sponsored Links
    #2  
Old 03-14-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 22 October 2014, 11:35 AM EDT
Location: Aachen, Germany
Posts: 4,414
Thanks: 73
Thanked 1,077 Times in 1,016 Posts
Had you told us what shell you are using, we had had the chance to help you.
E.g. for bash, the set command will set positional parameters, and ! will invoke history expansion (also indicated by the error msg).

For the purpose you have in mind, you don't need the parameters. If you need them, consider a shell function.
Sponsored Links
    #3  
Old 03-14-2013
mar85 mar85 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 22 August 2013, 10:09 PM EDT
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
Thanks RudiC for the reply. I'm a newbie in linux so pardon me if I don't provide enough info. Not sure which shell I'm running but I've run the command:

Code:
echo $shell

And here's the output:
/usr/.../pkgs/tcsh/6.13.00/bin/tcsh

Regarding the above alias error, what can I do to fix it and get it running?
    #4  
Old 03-14-2013
verdepollo's Avatar
verdepollo verdepollo is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 3 September 2014, 11:17 AM EDT
Location: Mexico
Posts: 725
Thanks: 11
Thanked 106 Times in 102 Posts
Wouldn't the alias you are attempting to create achieve exactly the same result as grep itself?

Why not just alias k 'grep -i' ?
Sponsored Links
    #5  
Old 03-15-2013
mar85 mar85 is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 22 August 2013, 10:09 PM EDT
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
Quote:
Wouldn't the alias you are attempting to create achieve exactly the same result as grep itself?

Why not just
Code:
alias k 'grep -i'

?
I think we can do it that way too, but for the sake of learning, just want to know how to use the
Code:
'set ARGS1 =(\!1); set ARGS2 =(\!2);

properly.
Sponsored Links
    #6  
Old 03-15-2013
grep_me grep_me is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 6 August 2014, 9:06 AM EDT
Location: INDIA
Posts: 43
Thanks: 8
Thanked 3 Times in 3 Posts
Rather than an alias, create a function for this (this is in korn shell)
k() { str="$1"; pth="$2; grep -i $str $pth ; }
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating .../ alias in bash kristinu Shell Programming and Scripting 3 01-20-2013 08:19 AM
Create alias files (not alias commands) Alexander4444 UNIX for Dummies Questions & Answers 3 04-16-2012 10:57 AM
Creating Alias for FILE newpromo Solaris 5 12-04-2009 11:10 AM
Creating alias for directory path jasjot31 UNIX for Dummies Questions & Answers 3 09-25-2006 08:04 AM
ifconfig: difference between creating logical or alias network interface zaff IP Networking 5 11-22-2005 09:28 AM



All times are GMT -4. The time now is 07:05 PM.