arrays.ion 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Standard Arrays
  2. let array = [1 [2 3] 4 [5 6]]
  3. for i in @array
  4. echo $i
  5. end
  6. for i in [1 [2 3] 4 [5 6]]
  7. echo $i
  8. end
  9. # Array Command Substitution
  10. let array_process = [ @(echo a b c d e) ]
  11. for i in @array_process
  12. echo $i
  13. end
  14. for i in @(echo a b c d e)
  15. echo $i
  16. end
  17. # Array Concatenation
  18. let new_array = [@array @array_process]
  19. for i in @new_array
  20. echo $i
  21. end
  22. # As Command Arguments
  23. echo @array
  24. echo @array_process
  25. echo @new_array
  26. # Slice by ID
  27. let array = [ 1 2 3 ]
  28. echo @array[0]
  29. echo @array[1]
  30. echo @array[2]
  31. echo [ 1 2 3 ][0]
  32. echo [ 1 2 3 ][1]
  33. echo [ 1 2 3 ][2]
  34. echo @(echo 1 2 3)[0]
  35. echo @(echo 1 2 3)[1]
  36. echo @(echo 1 2 3)[2]
  37. # Slice by Range
  38. let array = [ 1 2 3 4 5 ]
  39. echo @array[0..1]
  40. echo @array[0...1]
  41. echo @array[..3]
  42. echo @array[3..]
  43. echo @array[..]
  44. # Slice Syntax w/ variables
  45. for index in 0..3
  46. echo $(echo 😉😉😉)[$index]
  47. end
  48. # Convert Array to String
  49. let array = [ 1 2 3 4 5 ]
  50. let as_string = @array
  51. echo $as_string