Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You wrote:</p> <pre><code>if ["$var_check"=="c"];then </code></pre> <p>The <code>[</code> command is a command; its name must be surrounded by spaces (put simplistically).</p> <pre><code>if [ "$var_check" == "c" ]; then </code></pre> <p>The last argument, <code>]</code>, must also be preceded by a space. The operands within must also be space separated; they need to be separate arguments. The rules for the <code>[[ ... ]]</code> operator are a bit different, but using spaces helps people read the code even there. What you wrote is a bit like expecting:</p> <pre><code>ls"-l"/dev/tty </code></pre> <p>to work; it won't.</p> <p>You also need to double check whether your <code>test</code> or <code>[</code> operator supports <code>==</code>; the normal form is <code>=</code>.</p> <hr> <p>The line:</p> <pre><code>var_check= echo $str |awk -F . '{if (NF&gt;1) {print $NF}}' </code></pre> <p>This runs the <code>echo</code> command with <code>var_check</code> set as an environment variable, which is unlikely to be what you wanted. You almost certainly intended to write:</p> <pre><code>var_check=$(echo $str |awk -F . '{if (NF&gt;1) {print $NF}}') </code></pre> <p>This runs the <code>echo</code> and <code>awk</code> commands and captures the output in <code>var_check</code>. Use the <code>$(...)</code> notation in preference to the older but more complex to use <code>`...`</code> notation. In simple cases, they look the same; when you nest them, the <code>$(...)</code> notation is far, far simpler to understand and use.</p> <p>Also, looking on the larger scale (3 lines instead of just 1 line):</p> <pre><code>echo "enter file name" read num var_check=$(echo $str |awk -F . '{if (NF&gt;1) {print $NF}}') </code></pre> <p>You read the file name into variable <code>num</code>; you then echo <code>$str</code> instead of <code>$num</code>. If you've already got <code>$str</code> set somewhere earlier in the script (in unshown code), what you've got may be fine. Taken as a standalone fragment, it isn't right.</p> <p>You could also simplify the <code>awk</code> a little:</p> <pre><code>var_check=$(echo $str |awk -F . 'NF &gt; 1 {print $NF}') </code></pre> <p>This would work the same as what you wrote, but uses fewer parentheses and braces.</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.
 

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