0

To recreate this you will need to create a file named "l l.tex" in your home directory. Then make a an executable script with the following code

alacritty -e vim l\ l.tex

This opens the file, as I desired. Now create the following script

var="/home/l\ l.tex"
dar=$(echo $var | sed 's/\/home\//\@/g')
bar=$(echo $dar | sed 's/@//g')
alacritty -e vim $bar

This script, however, makes two new documents. However, they should be the same. I think there is an issue with how $bar is read. I am novice at this, but I reckon that this has to do with how strings are stored.

Can someone help me fix the second code so that I can use a variable?

Maths Wizzard
  • 221
  • 1
  • 6
  • Quote your variables. `echo $var` should be `echo "$var"` and `vim $bar` should be `vim "$bar"`. https://www.shellcheck.net would have found this error. – Socowi Jul 21 '22 at 07:58
  • Hi @Socowi, thanks for the comment. I did as you said, however, this still doesn't fix it. – Maths Wizzard Jul 21 '22 at 08:09
  • Drop the backslash in `var="/home/l\ l.tex"`. Inside double quotes, the backslash character preserves the literal value of the next character that follows, only if the next character is one of these characters: $ ` " \ or newline. Aside: You don't need the `sed` for this job. Try this: `var="/home/l l.tex"` and `alacritty -e vim "${var//\/home\/}"` – M. Nejat Aydin Jul 21 '22 at 08:14
  • Thank you for this. I also further realized that I had dash on my file.... Also, could you remove the duplicate mark and post your above comment as an answer so that I can accept it? – Maths Wizzard Jul 21 '22 at 08:34
  • Sorry, I forgot to mention the backslash in my comment. https://www.shellcheck.net/ prints a warning for it though. I could *vote* to re-open the question. But I doubt that enough others would vote too. And since there is now a marked duplicate for each of the problems, we should not re-open the question anyways. Your gratitude is appreciated though. – Socowi Jul 21 '22 at 09:15

0 Answers0