[X-Unix] Quoting in bash aliases

Eugene Lee list-themacintoshguy at fsck.net
Thu Feb 19 04:47:35 PST 2004


On Thu, Feb 19, 2004 at 01:28:32PM +0100, Kirk McElhearn wrote:
: 
: The following command replaces Mac line breaks with Unix line breaks:
: 
: perl -pi -e 's/\r\n?/\n/g'
: 
: I'd like to make an alias in bash, something like:
: 
: alias rplc='perl -pi -e 's/\r\n?/\n/g''
: 
: But the above doesn't work. I assume it has something to do with quoting.
: I've tried double-quotes, escaping the quotes in the perl string and more.
: 
: Can anyone tell me how this needs to be quoted to work correctly?

This worked for me at the command line:

	$ alias rplc="perl -pi -e 's/\r\n?/\n/g'"

Once the alias was created, this is how /bin/bash stored it:

	$ alias
	alias rplc='perl -pi -e '\''s/\r\n?/\n/g'\'''

However, you can use the rules of quoting to create an alias that is
easier to type and easier to read:

	$ alias rplc='perl -pi -e "s/\r\n?/\n/g"'


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/



More information about the X-Unix mailing list