title: How to building custom grep function
body: <p>I am new to bash, and I am trying to build my own grep alias to search through files
  here is the script I built:</p>
  
  <pre><code>function gia() {
    if [ -z "$1" ]; then
      echo "-You need to define what are you looking for-"
    else
      echo "-Looking for \"$1\".-"
      if [ -z $2 ]; then
        echo "-no path passed, searching all files-"
        grep -i --color "$1" ./*
      else
        echo "-Looking in \"$2\".-"
        grep -i --color "$1" $2
      fi
    fi
  }
  </code></pre>
  
  <p>the second option is not working well, if I try it, I get this output:</p>
  
  <pre><code>$$ gia 'sometext' ./*.html
  -Looking for "sometext".-
  -Looking in "./login.html".-
  </code></pre>
  
  <p>I never specified <strong>login.html</strong>, but it took one of the files in my directory and searched in it. and the grep fails.</p>
  
  <p>for example, if I have 3 files in <strong>myfiles</strong> directory:</p>
  
  <p><strong>1.html</strong>, <strong>2.txt</strong> and <strong>3.html</strong></p>
  
  <p>and 3.html has the text "backquotes"</p>
  
  <p>if I search like this:</p>
  
  <pre><code>cd myfiles
  gia 'backquotes'
  </code></pre>
  
  <p>I get the results</p>
  
  <pre><code>-Looking for "backquotes".-
  -no path passed, searching all files-
  ./3.html:    &lt;backquotes&gt;...&lt;/backquotes&gt;
  </code></pre>
  
  <p>but if I was on root, and search like this:</p>
  
  <pre><code>gia 'backquotes' ~/myfiles/*.html
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>-Looking for "backquotes".-
  -Looking in "./1.html".-
  </code></pre>
  
  <p>no results came back because it searched ONLY in 1.html. if I had "backquotes" in 1.html. it will come back, but i don't get anything from the other files, it's only searching in the first file and exits.</p>
  
  <p>I know the star is a special character in bash, but how can I solve this?</p>
  
  <p>Thanks for your help in advance.</p>
  
  <p>EMMNS</p>