Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can run,

 svn status |grep -v .jasper$ |cut -d ' ' -f8 |sed '/.*\..*/!d' |xargs ls -altr --color=auto

just fine. But when I go to add this as an alias (alias svtr="...") I get an error saying...

-bash: !d': event not found

Any ideas?

share|improve this question
up vote 2 down vote accepted

Using backslash \ to escape your ! should work.

alias svtr="svn status |grep -v .jasper$ |cut -d ' ' -f8 |sed '/.*\..*/\!d' |xargs ls -altr --color=auto"
alias svtr
alias svtr='svn status |grep -v .jasper$ |cut -d '\'' '\'' -f8 |sed '\''/.*\..*/\!d'\'' |xargs ls -altr --color=auto'

Actually, that just eliminates the error, because inside "" the shell tries to interpret !.

you may want to revert quotes (i.e., use singlequote to define alias, and use doublequote inside the aliased command, and escape singlequotes where necessary.

share|improve this answer
    
Thanks! The second solution worked after I removed the escape character in front of the !. – JJRhythm Jul 5 '12 at 18:56

The !d in your sed command is causing this, because ! is the Bash history expansion character. Temporarily turn off history expansion, like this:

set -H
alias svtr="..."
set +H

That should do it.

share|improve this answer
    
I tried this and received the same error. – JJRhythm Jul 5 '12 at 18:54
    
Sorry, but it works for me. – Fran Jul 6 '12 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .