0

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

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by landog
0

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

Edited by kingston123: n/a

0
# this example tests whether strng starts with the letter 'a'
   if [[ ${strng} == a* ]]    
   then

      echo ${strng}
   fi
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.