title: How can I set a default value when incorrect/invalid input is entered in Unix?
body: <p>i want to set the value of <strong>inputLineNumber</strong> to 20. I tried checking if no value is given by user by <strong>[[-z "$inputLineNumber"]]</strong> and then setting the value by <strong>inputLineNumber=20</strong>. The code gives this message <strong>./t.sh: [-z: not found</strong> as message on the console. How to resolve this? Here's my full script as well.</p>
  
  <pre><code>#!/bin/sh
  cat /dev/null&gt;copy.txt
  echo "Please enter the sentence you want to search:"
  read "inputVar"
  echo "Please enter the name of the file in which you want to search:"
  read "inputFileName"
  echo "Please enter the number of lines you want to copy:"
  read "inputLineNumber"
  [[-z "$inputLineNumber"]] || inputLineNumber=20
  for N in `grep -n $inputVar $inputFileName | cut -d ":" -f1`
  do
    LIMIT=`expr $N + $inputLineNumber`
    sed -n $N,${LIMIT}p $inputFileName &gt;&gt; copy.txt
    echo "-----------------------" &gt;&gt; copy.txt
  done
  cat copy.txt
  </code></pre>
  
  <hr>
  
  <p>Changed the script after suggestion from @Kevin. Now the error message <strong>./t.sh: syntax error at line 11: `$' unexpected</strong></p>
  
  <pre><code>#!/bin/sh
  truncate copy.txt
  echo "Please enter the sentence you want to search:"
  read inputVar
  echo "Please enter the name of the file in which you want to search:"
  read inputFileName
  echo Please enter the number of lines you want to copy:
  read inputLineNumber
  [ -z "$inputLineNumber" ] || inputLineNumber=20
  
  for N in $(grep -n $inputVar $inputFileName | cut -d ":" -f1)
  do
    LIMIT=$((N+inputLineNumber))
    sed -n $N,${LIMIT}p $inputFileName &gt;&gt; copy.txt
    echo "-----------------------" &gt;&gt; copy.txt
  done
  cat copy.txt
  </code></pre>