Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't want the back-quotes in the <code>until</code> line. You might write:</p> <pre><code>until grep -E "$pattern" "$part" do ...body of loop... done </code></pre> <p>Or you might add arguments to <code>grep</code> to suppress the output (or send the output to <code>/dev/null</code>). As written, the script tries to execute the output of the <code>grep</code> command and use the success/failure status of that (not the <code>grep</code> per se) as an indication of whether to continue the loop or not.</p> <p>Additionally, your pattern needs some work. It is:</p> <pre><code>pattern="^([0-9]{1}[0-9]*([km])$" </code></pre> <p>There is an unmatched open parenthesis in there. It also looks to me as though it is trying to allow a leading zero. You probably want:</p> <pre><code>pattern='^[1-9][0-9]*[km]$' </code></pre> <p>Single quotes are generally safer than double quotes for things like regular expressions.</p> <hr> <blockquote> <p>I just want to check if my variable called <code>part</code> is well-formed after writing it in Zenity entry dialog. I just realised that <code>grep</code> needs a file, but my <code>part</code> is a variable initialised in this script. How to get along now?</p> </blockquote> <p>In <code>bash</code>, you can use the <code>&lt;&lt;&lt;</code> operator to redirect from a string:</p> <pre><code>until grep -E "$pattern" &lt;&lt;&lt; "$part" </code></pre> <p>In most other shells, you'd write:</p> <pre><code>until echo "$part" | grep -E "$pattern" </code></pre> <p>This also works in <code>bash</code>, of course.</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.
    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