Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your script works fine for me on Linux with ksh 93t+.</p> <p>Since it's the same script and you're getting similar errors in two different environments, I would suspect stray characters in the file. Try one of these to show any stray characters that might be present:</p> <pre><code>hd filename cat -v filename hexdump -C filename </code></pre> <p>If it's simply a matter of DOS line endings, then this will fix that:</p> <pre><code>dos2unix filename </code></pre> <p><strong>Edit:</strong></p> <p>Here's one way to create and populate an associative array in ksh:</p> <pre><code>$ typeset -A testvar $ testvar=([one]="motherlode" [two]="vein" [waste]="tailings") $ echo ${testvar[two]} vein $ testvar[ore]="gold" $ echo ${!testvar[@]} # print the indices of the array one two waste ore $ typeset -p testvar # show the current definition of the array typeset -A testvar=([one]="motherlode" [two]="vein" [waste]="tailings" [ore]="gold") </code></pre> <p>As you can see, ksh uses bracketed subscripts for arrays. Dotted notation is used for accessing members of a <a href="http://www.informit.com/articles/article.aspx?p=99035&amp;seqNum=5" rel="nofollow noreferrer">compound variable</a>.</p> <p>I don't believe ksh functions can return arrays. However, you can use the print technique you have in your function (but add square brackets around the index name) and use <code>eval</code> to do the assignment.</p> <pre><code>$ typeset -A testvar $ eval "testvar=($(testfunc))" </code></pre> <p>or to append to an existing array:</p> <pre><code>$ eval "testvar+=($(testfunc))" </code></pre> <p>Unless your function is using associative arrays internally, you don't necessarily need to use them to build your output.</p> <p>However, if you do, you can parse from the result of <code>typeset -p</code>:</p> <pre><code>$ result=$(typeset -p env) $ result=${result#*\(} $ result=${result%\)*} $ print result </code></pre> <p>or iterate through the array:</p> <pre><code>$ for index in ${!env[@]}; do print -n "[$index]=${env[$index]} "; done; print </code></pre> <p>You may want to consult the documentation concerning discipline functions and type variables</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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