Hello,
I know this is a situation about the single quote and double literal, but I could not figure out after many search.
I need to loop through thousands of different BACs sequencing to optimize kmer individually.
IN=/PATH/TO/INPUT/FILES
for sample in S{01..1096}
do
run_program in='$IN/${sample}_file1.fa $IN/${sample}_file2.fa'
done
The package asks
in='input_file1 input_file2'
for the input files. Because of the single quote in the command option, the embedded shell variables cannot be interpreted literally. Is there a way to handle this situation?
Yes, I am aware of the difference. The problem I met is the $x should be changed each loop, but the single quote of the command parameter escaped the $ sign of $x. Maybe I should ask like this:
MYVAR=sometext
echo 'single quotes gives you $MYVAR'
Is there away to get output from the single quotes expression as the double quoted one? i.e.
echo 'single quotes gives you $MYVAR'
Output:
single quotes gives you sometext
I cannot change the single quote as it has been set by the package. Thanks again!
Thanks!
The awk examples seems a possible way to what I want, but not exactly. It seems there is no way to change the single quote literal in bash for my case. I thought there could be a way to get what I want. Waiting for more ideas.
Thanks a lot in advance!
Ah, how simple it is!!! It works now.
Does this replacement apply to all the case IF there is embedded variable inside the single quote in general? I mean generally.
Thanks a lot again!
Yes, 100% of the time, '$var' is interpreted as the literal four characters, the dollar sign retained, and "$var" is interpreted as a shell variable. The following examples show this:
In the final example, the shell tries to interpret $y as a variable. Since there is no such variable, the shell substitutes "nothing", and a blank line results.
This distinction between "single quotes" and 'double quotes' is really an important concept, so it's good you kept asking.
---------- Post updated at 02:53 PM ---------- Previous update was at 02:47 PM ----------
Just FYI, there is one additional case you probably already know about, but here goes anyway. You can use the \ "backslash" to "escape" the dollar sign, and prevent the shell from interpreting $var as a variable, as follows.
Important to note that this substitution happens right now. If you change the value of one of the variables used later, the other string won't alter with it.