Here is my code. I simply want to copy some files and replace a line in my Makefile. The parameter $1 is just the name of my new .tex file.
#!/bin/bash
pwd="./"
tex=".tex"
pwd=$1$tex
cp ~/TeX/matt.sty .
cp ~/TeX/mon.tex $pwd
cp ~/TeX/Makefile .
sed="sed 's/mon.tex/"$1$tex"/g' Makefile > Makefile"
$sed
I’ve the following error : sed: 1: "'s/mon.tex/salut.tex/g'": invalid command code '
ps: i’m using sed on Mac OS X. (so it’s bsd sed)
The first argument to sed is literally
's/mon.tex/"$1$tex"/g'(with single quotes). obviously sed cannot parse that as a command.Removing the single quotes would solve that problem but redirection (
>) still won’t work.Just run the sed command directly (what’s the point of the
$sedvariable? i don’t get it)Note: to modify a file with sed, use
sed -i. Redirecting to the same file you are processing won’t work.