|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
Quote:
Code:
'set ARGS1 =(\!1); set ARGS2 =(\!2); properly. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|