Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Even though the answer's already accepted, here's another method for those who need to preserve newlines and special characters like Escape ( <code>\033</code> ): Storing the variable in <strong>base64</strong>.</p> <p>You need: <strong>bc, wc, echo, tail, tr, uuencode, uudecode</strong></p> <h2>Example</h2> <pre><code>#!/bin/sh #====== Definition =======# varA="a b c" # uuencode the variable varB="`echo "$varA" | uuencode -m -`" # Skip the first line of the uuencode output. varB="`NUM=\`(echo "$varB"|wc -l|tr -d "\n"; echo -1)|bc \`; echo "$varB" | tail -n $NUM)`" #====== Access =======# namevar1=varB namevar2=varA echo simple eval: eval "echo \$$namevar2" echo simple echo: echo $varB echo precise echo: echo "$varB" echo echo of base64 eval "echo \$$namevar1" echo echo of base64 - with updated newlines eval "echo \$$namevar1 | tr ' ' '\n'" echo echo of un-based, using sh instead of eval (but could be made with eval, too) export $namevar1 sh -c "(echo 'begin-base64 644 -'; echo \$$namevar1 | tr ' ' '\n' )|uudecode" </code></pre> <h2>Result</h2> <pre><code>simple eval: a b c simple echo: YQpiCmMK ==== precise echo: YQpiCmMK ==== echo of base64 YQpiCmMK ==== echo of base64 - with updated newlines YQpiCmMK ==== echo of un-based, using sh instead of eval (but could be made with eval, too) a b c </code></pre> <h2>Alternative</h2> <p>You also could use the <code>set</code> command and parse it's output; with that, you don't need to treat the variable in a special way before it's accessed.</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.
    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