Advertisement
What_Ever

Arrays

Aug 13th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.38 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. colors=(red blue green black purple yellow)
  4. idx=0
  5. echo ${#colors[*]}
  6. while [ $idx -lt ${#colors[*]} ]
  7. do
  8.     echo ${colors[$idx]}
  9.     idx=`expr $idx + 1`
  10. done
  11.  
  12. echo
  13.  
  14. #print the strings in the array and their lengthes
  15. for idx in ${!colors[*]}
  16. do
  17.     echo ${colors[$idx]} ${#colors[$idx]}
  18. done
  19.  
  20. echo
  21.  
  22. for item in ${colors[*]}
  23. do
  24.     echo $item
  25. done
  26.  
  27. echo
  28.  
  29. echo ${colors[*]}
  30.  
  31. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement