goal
In the ZSH script for these arguments, I want to get the first line and the rest.
For example, when the script is named test
sh test hello
supposed to extract h and ello .
http://zsh.sourceforge.net/Doc/zsh_a4.pdf
He speaks:
A signature can also be performed for values without an array, in which case the indices determine the substring to be extracted. For example, if FOO is set to "foobar", then "echo $ FOO [2,5] prints" Ooba.
Q1
So I wrote a shell script in a file called test
echo $1 echo $1[1,1]
Terminal:
$ sh test hello hello hello[1,1]
the result fails. What is wrong with the code?
Q2
Also I don't know how to extract subString from n to the last. Perhaps I need to use array partitioning with regex?
EDIT: Q3
This may be another question, so if you need to start a new Thread, I will do it.
Thanks @skishore Here is another 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
I'm not sure how to compare string values with string, but for given arguments hello
result:
command not found: h
What is wrong with the code?
EDIT2:
What I found correctly
#! /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
EDIT3:
As a result of the whole, this is what I did with this question.
GitSnapShot is a thin ZSH shell for Git commands to simplify and simplify use