I need to read and display the text of a shell script that contains shell variables e.g. the line:

p=`dirname ${0}`

My InstallBuilder script looks like this:

<readFile>
    <name>file_content</name>
    <path>${filePath}</path>
</readFile>
<showText>
    <text>${file_content}</text>
    <title>${filePath}</title>
</showText>

InstallBuilder obviously evaluates the file text for <showText> e.g. the variable ${0} which does of course not exist. So the above line is displayed as

p=`dirname ***unknown variable 0***`

Is it possible to display the text as plain text without InstallBuilder trying to evaluate variables in the text?

asked 05 Jul '12, 05:50

twiga's gravatar image

twiga
30224
accept rate: 0%


This is a current limitation. You could use the below custom action, and use <readFileEscapeVars> instead of <readFile>:

<project>
     ...
    <functionDefinitionList>
      <actionDefinition>
        <name>readFileEscapeVars</name>
        <actionList>
          <globalVariables names="${variable}"/>
          <createTimeStamp variable="timestamp"/>
          <setInstallerVariable name="tmpFile" value="${system_temp_directory}/tmp-${timestamp}.txt"/>
          <copyFile origin="${file}" destination="${tmpFile}"/>
          <substitute>
            <files>${tmpFile}</files>
            <type>exact</type>
            <substitutionList>
              <substitution pattern="${" value="@@DOLLAR_CHAR@@{"/>
            </substitutionList>
          </substitute>
          <readFile name="${variable}" path="${tmpFile}"/>
          <setInstallerVariableFromRegEx>
            <name>${variable}</name>
            <pattern>@@DOLLAR_CHAR@@\{([^\n\}]*)\}</pattern>
            <substitution>@@VAR_REFERENCE@@(\1)</substitution>
            <text>${${variable}}</text>
          </setInstallerVariableFromRegEx>
          <setInstallerVariableFromRegEx>
            <name>${variable}</name>
            <pattern>@@DOLLAR_CHAR@@</pattern>
            <substitution>$</substitution>
            <text>${${variable}}</text>
          </setInstallerVariableFromRegEx>
          <setInstallerVariableFromRegEx>
            <name>${variable}</name>
            <pattern>@@VAR_REFERENCE@@\(([^\)]*)\)</pattern>
            <substitution>${'${'${\1}'}'}</substitution>
            <text>${${variable}}</text>
          </setInstallerVariableFromRegEx>
          <deleteFile path="${tmpFile}"/>
        </actionList>
        <parameterList>
          <stringParameter name="file" value="" default=""/>
          <stringParameter name="variable" value="" default=""/>
        </parameterList>
      </actionDefinition>
    </functionDefinitionList>
   <initializationActionList>
        <readFileEscapeVars file="${filePath}" variable="file_content"/>
        <showText>
            <text>${file_content}</text>
            <title>${filePath}</title>
        </showText>
    </initializationActionList>
</project>
link

answered 05 Jul '12, 07:14

juanjo's gravatar image

juanjo ♦♦
5.8k413
accept rate: 23%

Thank you Juanjo, that's awesome and works like a charm.

(05 Jul '12, 09:12) twiga
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5
×2

Asked: 05 Jul '12, 05:50

Seen: 1,379 times

Last updated: 05 Jul '12, 09:12