As everyone already commented, it's not about removing the '"'
but to quote your $i
inside double quotes. Nor is it a random combination of " and ' to make it work.
Explanations :
When i
contains a space like : i="1.19 Sodium"
(here the double quotes are delimiters, not characters of the string),
the line ln -s saves '"'${i}/.minecraft/saves'"'
is seen as :
ln -s saves '"'1.19 Sodium/.minecraft/saves'"'
In this context, single quotes are string delimiters, while double quotes are any (unwanted) characters in the string.
It is read as :
- The word
ln
,
- A field separator,
- The word
-s
,
- A field separator,
- The word
saves
,
- A string (delimited by single quotes) of one character
"
concatenated to the word 1.19
,
- The space (coming from
i
) interpreted (since outside quotes) as a field separator,
- The word
Sodium/.minecraft/saves
concatenated to a string (delimited by single quotes) of one character "
.
Then it's exactly equivalent to :
ln -s saves '"1.19' 'Sodium/.minecraft/saves"'
Which is not what you want, and why the error message says Sodium/.minecraft/saves"
does not exist.
As @tkausl commented, the solution is "${i}/.minecraft/saves"
(or without the braces "$i/.minecraft/saves"
).
With this, when i
contains a space like : i="1.19 Sodium"
,
the line ln -s saves "$i/.minecraft/saves"
is seen as :
ln -s saves '1.19 Sodium/.minecraft/saves'
,
- or (equivalent)
ln -s saves "1.19 Sodium/.minecraft/saves"
,
- or (equivalent)
ln -s saves 1.19\ Sodium/.minecraft/saves
.
With the correction, any space in i
will no longer be interpreted as a field separator because i
is in a string delimited by double quotes.
Conclusion: Never use non-quoted variables (even echo "$i"
instead of echo $i
).