title: ZSH subString extraction
body: <h2>Goal</h2>
  
  <p>In <strong>ZSH</strong> script, for a given args, I want to obtain the first string and the rest.</p>
  
  <p>For instance, when the script is named <code>test</code></p>
  
  <pre><code>sh test hello
  </code></pre>
  
  <p>supposed to extract <code>h</code> and <code>ello</code>.</p>
  
  <h2><a href="http://zsh.sourceforge.net/Doc/" rel="noreferrer">ZSH manual</a></h2>
  
  <p><a href="http://zsh.sourceforge.net/Doc/zsh_a4.pdf" rel="noreferrer">http://zsh.sourceforge.net/Doc/zsh_a4.pdf</a></p>
  
  <p>says:</p>
  
  <blockquote>
    <p>Subscripting may also be performed on non-array values, in which case the subscripts specify a
    substring to be extracted. For example, if FOO is set to ‘foobar’, then ‘echo $FOO[2,5]’ prints
    ‘ooba’.</p>
  </blockquote>
  
  <h2>Q1</h2>
  
  <p>So, I wrote a shell script in a file named <code>test</code></p>
  
  <pre><code>echo $1
  echo $1[1,1]
  </code></pre>
  
  <p>terminal:</p>
  
  <pre><code>$ sh test hello
  hello
  hello[1,1]
  </code></pre>
  
  <p>the result fails. What's wrong with the code?</p>
  
  <h2>Q2</h2>
  
  <p>Also I don't know how to extract subString from n to the last. Perhaps do I have to use Array split by regex?</p>
  
  <h2>EDIT: Q3</h2>
  
  <p>This may be another question, so if it's proper to start new Thread, I will do so.</p>
  
  <p>Thanks to  @skishore Here is the further code</p>
  
  <pre><code>#! /bin/zsh
  
  echo $1
  
  ARG_FIRST=`echo $1 | cut -c1`
  ARG_REST=`echo $1 | cut -c2-`
  echo ARG_FIRST=$ARG_FIRST
  echo ARG_REST=$ARG_REST
  
  if $ARG_FIRST = ""; then
    echo nullArgs
  else
    if $ARG_FIRST = "@"; then
      echo @Args
    else
      echo regularArgs
    fi
  fi
  </code></pre>
  
  <p>I'm not sure how to compare string valuables to string, but for a given args <code>hello</code></p>
  
  <p>result:</p>
  
  <pre><code>command not found: h
  </code></pre>
  
  <p>What's wrong with the code?</p>
  
  <h2>EDIT2:</h2>
  
  <p>What I've found right</p>
  
  <pre><code>#! /bin/zsh
  
  echo $1
  
  ARG_FIRST=`echo $1 | cut -c1`
  ARG_REST=`echo $1 | cut -c2-`
  echo ARG_FIRST=$ARG_FIRST
  echo ARG_REST=$ARG_REST
  
  if [ $ARG_FIRST ]; then
    if [ $ARG_FIRST = "@" ]; then
      echo @Args
    else
      echo regularArgs
    fi
  else
    echo nullArgs
  fi
  </code></pre>
  
  <h2>EDIT3:</h2>
  
  <p>As the result of whole, this is what I've done with this question.</p>
  
  <h3><a href="https://github.com/kenokabe/GitSnapShot" rel="noreferrer">https://github.com/kenokabe/GitSnapShot</a></h3>
  
  <p><strong>GitSnapShot</strong> is a ZSH thin wrapper for Git commands for easier and simpler usage</p>