954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

test first char in array

How do I test whether the first character in an array is a particular character?

i=0
while [ $i -lt $# ]; do
   strng=${args[i]};
   if [ $strng[0] == '-' ]
      echo  ${array[i]}
   let i=i+1
done


Better yet - can I test the first character in an array of strings for a match?

i=0
while [ $i -lt $# ]; do
   array[i]=${args[i]};
   if [ $array[i][0] == '-' ]
      echo  ${array[i]}
   let i=i+1
done

Thanks,
-dog

landog
Newbie Poster
4 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

thanks for sharing about this test.i am new user and looking for this.

kingston123
Newbie Poster
1 post since Jun 2011
Reputation Points: 8
Solved Threads: 1
 
# this example tests whether strng starts with the letter 'a'
   if [[ ${strng} == a* ]]    
   then

      echo ${strng}
   fi
landog
Newbie Poster
4 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You