Note that there are some explanatory texts on larger screens.

plurals
  1. POUNIX : Substitute value of variable inside script
    primarykey
    data
    text
    <p>I may not have got the title perfect for this question, but I am wondering if there is a way to do the following :</p> <p>Basically, I have a text file with some key value pairs and also a statement (in the same text file) which will be extracted by a shell script and which needs to also simultaneously substitute the A, B, C in the STATEMENT variable .</p> <p>To make things simple, let me provide an example. </p> <p>Here is my text file :</p> <p>File : values.txt</p> <pre><code>A=1 B=2 C=3 STATEMENT=apple A orange B grape C </code></pre> <p>Also, I have a shell script which extracts these values and the statement from the text file and uses the STATEMENT variable as a parameter to another script it calls, something like:</p> <p>Script : first_script.sh</p> <pre><code>A=`cat values.txt | grep -w '^A' | cut -d'=' -f2` B=`cat values.txt | grep -w '^B' | cut -d'=' -f2` C=`cat values.txt | grep -w '^C' | cut -d'=' -f2` STATEMENT=`cat values.txt | grep -w 'STATEMENT' | cut -d'=' -f2` second_script.sh $STATEMENT </code></pre> <p>As you can see, second_script is called from within first_script and it uses the STATEMENT variable, so what I <strong>expect to see</strong> with the second_script call is :</p> <pre><code>second_script.sh apple 1 orange 2 grape 3 </code></pre> <p>Note that "A", "B" and "C" should get substituted to their values 1, 2 and 3.</p> <p>However, what I get is still :</p> <pre><code>second_script.sh apple A orange B grape C </code></pre> <p>which is what I don't want. </p> <p>How do I make sure that A, B and C get substituted to 1,2 and 3 respectively when second_script is called from first_script ? </p> <p>Sorry to make it confusing. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload