How to make this an alias in zsh?

svn status | grep "^?" | awk -F "      " '{print $2}' | tr "\n" "\0" | xargs -0 svn add

I know it should be something along the lines:

alias sall = "the command"

But as the line mixes " with ' I don't know how to handle that.

link|improve this question

feedback

2 Answers

up vote 4 down vote accepted

You can use " for your awk command.

alias sall='svn status | grep "^?" | awk -F " " "{print $2}" | tr "\n" "\0" | xargs -0 svn add'

should work.

link|improve this answer
The escaped characters version gives an error about a ' not being matched. But the first version works, if you make it alias sall='svn st...' (no whitespace) – Nerian Feb 17 '11 at 17:54
@Nerian: If you use double quotes around the awk command, you'll need to escape the dollar sign: awk -F " " "{print \$2}" – Dennis Williamson Feb 17 '11 at 17:55
@Dennis: umm, works for me without backslash – Olli Feb 17 '11 at 17:55
1  
@Nerian: true, fixed. – Olli Feb 17 '11 at 17:56
2  
Sorry, Bash needs it. Apparently zsh doesn't. After trying both, I see the difference. – Dennis Williamson Feb 17 '11 at 17:57
feedback

Use a function.

sall() {
    svn status | sed -rn 's/^\? {7}//p' | xargs -d '\n' svn add
}

(Since svn uses newline as output separator, it makes no sense to convert it to null and back.)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.