James Bond James Bond - 1 month ago 6x
Bash Question

emacs --eval '(ediff "$1" "$2")' how to put this line in to shell-script?

I want to put the following line:

emacs --eval '(ediff "$1" "$2")'

into a shell script, so I dont need to write this long and complicated line everytime. However, when I put it into my shell script as it is, I get an error:

ediff-find-file: File `$1' does not exist or is not readable

I guess there is some sort of
escaping problem here and I need to put some
in this line. What exactly do I need to fix?

fge fge

This is normal, your string is surrounded with single quotes, and variables are not expanded within single quotes.

You should use double quotes so that they get expanded, and escape existing double quotes in the string:

emacs --eval "(ediff \"$1\" \"$2\")"

It is worth noting that when expanding variables, only the outer quotes matter. That is:

$ A=foo
$ echo "'$A'"

will print 'foo'. The fact that single quotes surround $A here does not matter: the outer quotes are double quotes.