I have files molecule416_out.pdbqt, where I am using variable i (molecule$i_out.pdbqt) to loop over all files. But it looks like it is reading the variable as i_out instead of just i. Since all those files are results of long simulations so can't rerun them to remove that underscore from out files. Is there any quick fix? Thanks.
Asked
Active
Viewed 45 times
0
-
Use `${i}_out....` – Edgar Magallon Oct 22 '22 at 05:15
-
The answer below is good but also see [What is the best practice between using ${var} or $var? [duplicate]](https://unix.stackexchange.com/q/288643) and the dupe it links to: [$VAR vs ${VAR} and to quote or not to quote](https://unix.stackexchange.com/q/4899). In short: always double-quote your variables and use `{}` when you need to separate a variable name from immediately adjacent text that happens to be valid characters for variable names. – cas Oct 22 '22 at 13:09
1 Answers
2
Use molecule${i}_out.pdbqt The ${varname} syntax delimits the part of the string that is the variable name, so the shell can do what you intend.
Sotto Voce
- 3,664
- 1
- 8
- 21