Home > scripts > How to make this "svngrep" alias work on ".bash_aliases"?

How to make this "svngrep" alias work on ".bash_aliases"?

September 17Hits:2
Advertisement

I added to following line to the "~/.bash_aliases" file:

alias svngrep='grep -R $1 ./* --exclude-dir ".svn"' 

but it's not working.

It outputs (in my translation to English):

svngrep test grep: test: File or directory not found 

But with the full "grep" line it works just fine.

Any idea what's wrong with my alias?

Answers

$1 does not work in an alias. You need to define a function for that, for example in your .bashrc file.

function svngrep { grep -R --exclude-dir=".svn" "[email protected]" . ; }

This should do the trick! However, make sure that your old alias is not around before trying it out from the command line:

unalias svngrep
function svngrep { grep -R --exclude-dir=".svn" "[email protected]" . ; }
svngrep "teststring"

Quoting bash manual:

There is no mechanism for using arguments in the replacement text. If arguments are needed, a shell function should be used (...) For almost every purpose, aliases are superseded by shell functions.

You don't need a bash function (you may use it though, matter of taste), just remove the $1 ./* from your example and call it this way:

alias svngrep='grep -R --exclude-dir ".svn"'
svngrep phrase .

or here's an example I've been using for months:

alias rg='rgrep --exclude-dir=.svn --exclude=*.pyc'
rg phrase .

Of course, you can substitute . with any directory. I'd say using aliases is more intuitive, alias is an alias, function can do anything.

Tags:alias, scripts

Related Articles

  • How to make this "svngrep" alias work on ".bash_aliases"?September 17

    I added to following line to the "~/.bash_aliases" file: alias svngrep='grep -R $1 ./* --exclude-dir ".svn"' but it's not working. It outputs (in my translation to English): svngrep test grep: test: File or directory not found But with

  • rm -i alias not working with sudo as rootDecember 1

    I have noticed in all my Ubuntu servers the alias rm -i is ignored when you run sudo rm * as root. Is there something in sudo that is causing this behavior? I know you don't need to use sudo when you are root however in the event that a Jr SA were to

  • How to alias cp with cp -i by defaultJune 7

    Is there a good way to alias the command cp file1 file2 to cp -i file1 file2? Apologies if this is a dumb question, I'm a Unix novice. --------------Solutions------------- You should put an alias in your start up script: alias cp='cp -i' You can put

  • How to make an alias active in both current session and in .bashrc at same time?January 9

    I just found frequently I decide to add an alias for longer time use at the same time use it now. So I have to type the same thing twice, first in current bash session then .bashrc. --------------Solutions------------- Define this function (say, in y

  • How to add an alias without directly editing the `bash_aliases` file?February 1

    Is there a way to add an alias from the command line without directly editing the bash_aliases file? To clarify, how can I make a bash script do it without having to enter something along the lines of nano bash_aliases to add them? --------------Solu

  • How to create a permanent alias without resourcing the .bashrc-like file?March 28

    I really like bash aliases, it annoys me that every time I want to add a new alias I have type two commands: echo "alias \"short-cmd\"='long-command'" >> ~/.bash_aliases source ~/.bash_aliases Any way I can create an alias perman

  • How to easily make an alias command permanent? August 5

    This question already has an answer here: How do I create a permanent Bash alias? 8 answers I search everywhere and almost everyone was suggesting to open the ~/.bashrc or ~/.bash_aliases, then put the alias command there, I created a function name p

  • Automatically put an alias into ~/.bashrc or ~/.zshrc September 5

    This question already has an answer here: Are there any utilities to quickly add, list and remove command aliases? 2 answers Is there a command line util/script that automatically saves aliases? E.g. save-alias my-ip="curl ipecho.net/plain" and

  • How would I create an alias to run a game? (Minecraft)February 27

    I would like to create a command-line alias to run a game (Minecraft in particular). How would I accomplish this? I want to type in runmc to run the command java -jar /root/.minecraft/launcher.jar. I already put the following into my .bashrc file ali

  • How to make an alias permanent?July 14

    I have created an alias: alias shh='sqlplus hfdora/[email protected]" After creating this alias I was able to enter my database only by typing shh. But after closing my shell, I wasn't able to find the alias next time. Even after typing only alias, shh was

  • Create a clickable desktop shortcut for an alias

    Create a clickable desktop shortcut for an aliasDecember 18

    For example, let's say I have defined an alias under my .bash_aliases, alias gotoheaven="xdg-open /path/to/heaven" now I wish to create a clickable icon for it on the desktop. [I know make link to create folder shortcut, but this I am asking is

  • Favorite Unix command line aliases? May 30

    What are your favorite command line aliases (bash/sh/tcsh) aliases? Here are a few of mine. alias lsr='ls -lrt' alias gon='cd $HOME/Notes' alias devdb='mysql -h dev --user=x --password=secret dbname' alias ec='rm *~'; # emacs cleanup alias h='history

  • Why terminal shows "/home/igoru /etc/bash_completion" every time I open it?August 21

    I've added some lines to ~/.bash_aliases yesterday... And today my gnome-terminal started showing me this expression in the beginning, just before the prompt. /home/igoru /etc/bash_completion [email protected]: Those are the lines I added: alias rea

  • Which aliases do you find most useful or helpful to your Ubuntu experience?January 12

    Since first becoming an Ubuntu user I have developed a growing list of aliases, and there are some that I cannot imagine being without. This makes me think that there are probably still tons of aliases that I haven't thought to use which could make t

  • Can I make scripts use aliases instead of commands?March 2

    I have an alias for a command (I'm setting up a Python development environment) alias python=~/virtualenv/bin/python so that I can run ~/virtualenv/bin/python by just typing python. Now in my project there is a shell script that goes, for example: #!

  • How to open a PDF file from terminal?May 16

    I used to work on the Mac terminal before and I used: open file2open.pdf and the PDF file would be opened on preview or whatever my default viewer was. When I use it in the terminal in Ubuntu I get this error message: Couldn't get a file descriptor r

  • How to make bash aliases available as linux commands?September 5

    I have many bash aliases on a remote location. But when I try to run those from my local linux box, I get the 'command not found' error. e.g. $ ssh [email protected] 'status' bash: status: command not found On the remote location, status is defined as $ al

  • Command for deleting temporary files ending with ~December 28

    Many days ago, I found this useful bash alias (contents of my ~/.bash_aliases) # aliases # finds temporary files ending with '~' and deletes them alias rm~='find . -name '*~' -print0 | xargs -0 /bin/rm -f' Now I tried to use rm~ after cd to some dire

  • How to print the percentage of disk use from `df -hl`February 14

    I know that df -hl outputs a list of all my partitions with its size, usage as a percentage, and space available. If I wanted to output just the size and usage as a percentage of sda2 and sda3, for example, how could I tell Linux (Ubuntu) to check th

  • How to run source on terminal start up?August 20

    I have alias ready on .bash_aliases. Problem I'm having right now is that I need to run source ~/.<filename> first before I can execute the alias command. My question would be how do I run the source ~/.<filename> when user opens terminal. ---

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.543 s.