views:

1280

answers:

2

I'm trying to run the following commands:

replace -x "must " A2input.txt
replace -x " a" -f -s ## A2input.txt
replace -x to -s ## -a A2input.txt
replace -x faith -f "unequivocal" A2input.txt

And it'd be nice if I could just alias it to something short and simple like "a", "b", "c", "d", etc...

However, some of those arguments have a quote, which is messing up the alias. Does anyone know how to actually escape the double quotes? I've tried things like '\"' and \" but nothing seems to work.

I'm using tcsh as my shell.

A: 

If you can't get an alias to work, just write a short shell script, chmod +x, and put it somewhere in your $PATH (like $HOME/bin):

#!/bin/tcsh
replace -x "must" ...

I don't have any experience with tcsh, but with bash you do it like any of these:

alias t='echo "hello  world"'     # using single quotes to enclose entire string
alias t=echo\ \"hello\ \ world\"  # escape " and <space>
alias t="echo \"hello  world\""   # double-quote + escape inner double quotes

Maybe something similar will work in tcsh?

derobert
+1  A: 

I got it to work by storing the string with the double quote in a variable with the string surrounded by single quotes. When I use the variable I up inside single quotes.
Example:

[11:~] phi% 
[11:~] phi% set text = 'a quote "'
[11:~] phi% alias ec echo '$text'
[11:~] phi% ec
a quote "
[11:~] phi% 
[11:~] phi% alias ec echo this has '$text'
[11:~] phi% ec
this has a quote "
[11:~] phi% 

I tested this with tcsh on OSX

phi