0
votes

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?

Quote your variables. echo $var should be echo "$var" and vim $bar should be vim "$bar". shellcheck.net would have found this error. - Socowi
Hi @Socowi, thanks for the comment. I did as you said, however, this still doesn't fix it. - Maths Wizzard
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
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
Sorry, I forgot to mention the backslash in my comment. 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