321d08dbad2770da0994b5f53bc8757a

I looking for a quick easy way to change this command. I would like to use the !! command with bash to put the -i at the correct place:

#This is the error command
egrep "smtp" -i ./production.log

#Would like to correct it with !! to have this: (whitout taping it again)
egrep -i "smtp" ./production.log

Refactorings

No refactoring yet !

9992e9f44a75ef4248d687fd18745881

GeekBoi

July 29, 2009, July 29, 2009 19:20, permalink

No rating. Login to rate!

Not sure that it saves you that much but here is one option.

#This is the error command
egrep "smtp" -i ./production.log

# Have to type the command again rather than useing !! then append the arguments from the previous command.
egrep !:2 !:1 !:3
C28154df962ab32ffe9a4767e2efd8a9

Pascal Charest

September 9, 2009, September 09, 2009 19:31, permalink

No rating. Login to rate!

Here, add this function to your $home/.bashrc file. This will intercept any call made through the shell to egrep and rewrite it if needed. It catch the case where $2 is -i and rewrite the command.

You must validate that egrep is present at /bin/egrep (could refactor to add the which function).

function egrep {
        echo "command used:"
        echo "egrep" $@

        if [ $2 = "-i" ]
                then
                echo "wrong syntax, we are rebuilding"
                /bin/egrep $2 $1 $3
        else
                /bin/egrep $@
        fi

}

Your refactoring





Format Copy from initial code

or Cancel