Note that there are some explanatory texts on larger screens.

plurals
  1. POCounting Whitespace in Arguments in KSH?
    primarykey
    data
    text
    <p>I am trying to allow strings that have whitespace in them to be counted as whole strings, rather than being parsed. This is what I would like to have happen:</p> <pre><code>$ ksh program.ksh "what up" File 'what up' not found. </code></pre> <p>And this is what I am getting:</p> <pre><code>$ ksh program.ksh "what up" File 'what' not found. File 'up' not found. </code></pre> <p>This is the code I've tried to make work:</p> <pre><code>wflag=false cflag=false while getopts "cw" opt; do case "$opt" in c) cflag=true ;; w) wflag=true ;; /?) ;; esac done </code></pre> <p>The problem lies when 1) I try something above like <code>ksh program.ksh "what up"</code>, and 2) when I try something like <code>ksh program.ksh "-w -c"</code>. The second one is most confusing, as when I print out <code>wflag</code> and <code>cflag</code> they are both true. Shouldn't <code>"-w -c"</code> be treated as a string here? It seems as though the kernel (is it the kernel doing the work here?) is parsing this, although that is exactly what I don't want; I want it to be treated as a string with whitespace. I have read through <a href="http://mywiki.wooledge.org/WordSplitting" rel="nofollow">WordSplitting</a> and ((the article on Arguments, wouldn't let me post it though)), and <em>think</em> I understand it. Clearly I must be missing something, or not really understanding it after all :P</p> <p>My instinct tells me there is something happening with <code>getopts</code> that automatically gets rid of any whitespace. I have tried <code>$(opt)</code> instead of <code>"$opt"</code>, as well as with curly braces and/or single quotes (I'm pretty sure single quotes is not what would work though). Alas, no cigar.</p> <p>Any help would be greatly appreciated, and thank you for reading through this wall of text.</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. 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