Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Counter-example:</p> <pre><code>$ cat file.txt hello;welt; hello;world; hell;welt; $ cat xx.sh grep "$1;$2" file.txt $ bash -x xx.sh hello welt + grep 'hello;welt' file.txt hello;welt; $ </code></pre> <p>You have not yet classified your problem accurately.</p> <hr> <blockquote> <p>If you try to assign the result of grep to a variable (like I do) your example breaks.</p> </blockquote> <p>Please show what you mean. Using the same data file as before and doing an assignment, this is the output I get:</p> <pre><code>$ cat xx.sh grep "$1;$2" file.txt output=$(grep "$1;$2" file.txt) echo "$output" $ bash -x xx.sh hello welt + grep 'hello;welt' file.txt hello;welt; ++ grep 'hello;welt' file.txt + output='hello;welt;' + echo 'hello;welt;' hello;welt; $ </code></pre> <p>Seems to work for me. It also demonstrates why the question needs an explicit, complete, executable, minimal example so that we can see what the questioner is doing that is different from what people answering the question think is happening.</p> <hr> <p>I see you've provided some sample code:</p> <pre><code># find entry $line=$(grep "$1;$2;" $PERMISSIONSFILE) # splitt line reads=$(echo $line | cut -d';' -f3) writes=$(echo $line | cut -d';' -f4) admins=$(echo $line | cut -d';' -f5) </code></pre> <p>The line <code>$line=$(grep ...)</code> is wrong. You should omit the <code>$</code> before <code>line</code>. Although it is syntactically correct, it means 'assign to the variable whose name is stored in <code>$line</code> the result of the <code>grep</code> command'. That is unlikely to be what you had in mind. It is, occasionally, useful. However, those occasions are few and far between, and only for people who know what they're doing and who can document accurately what they're doing.</p> <p>For safety if nothing else, I would also enclose the <code>$line</code> values in double quotes in the <code>echo</code> lines. It may not strictly be necessary, but it is simple protective programming.</p> <p>The changes lead to:</p> <pre><code># find entry line=$(grep "$1;$2;" $PERMISSIONSFILE) # split line reads=$( echo "$line" | cut -d';' -f3) writes=$(echo "$line" | cut -d';' -f4) admins=$(echo "$line" | cut -d';' -f5) </code></pre> <p>The rest of your script was fine.</p>
 

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