Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash alias command with both single and double quotes

I have this command that does what I want but I can't get to alias it in my .bashrc (note that it uses both single and double quotes):

svn status | awk '$1 =="M"{print $2;}' 

I've tried:

alias xx="svn status | awk '$1 ==\"M\"{print $2;}'" 

And some other common sense combinations with no luck.. I know that bash is very picky with quotes.. So what's the correct way to alias it and why ? Thanks

like image 536
pragmatic_programmer Avatar asked Nov 21 '13 02:11

pragmatic_programmer


People also ask

How do you escape a quote in alias in bash?

If it's bash , variables need to be quoted. In a function, no need to put everything on one line. Show activity on this post. It's simply done by finishing already opened one ( ' ), placing escaped one ( \' ), then opening another one ( ' ).

Can an alias run multiple commands?

An alias can be created with more than two commands. Similar to the two command method multiple commands can be used for an alias. We again use the semi-colon in order to use and separate multiple commands from each other.

Can a bash alias take argument?

Bash users need to understand that alias cannot take arguments and parameters. But we can use functions to take arguments and parameters while using alias commands.


1 Answers

You just need to escape it correctly.

alias xxx="svn status | awk '\$1 ==\"M\"{print \$2;}'" 
like image 178
ffledgling Avatar answered Oct 16 '22 08:10

ffledgling