array_test.ion 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. echo '# ANCHOR: standardArrays'
  2. let array = []
  3. echo @array
  4. let array = [1]
  5. for i in @array
  6. echo $i
  7. end
  8. let array = [1 [2 3] 4 [5 6]]
  9. for i in @array
  10. echo $i
  11. end
  12. for i in [1 [2 3] 4 [5 6]]
  13. echo $i
  14. end
  15. echo '# ANCHOR_END: standardArrays'
  16. echo '# ANCHOR: command_substitution'
  17. let array_process = [ @(echo a b c d e) ]
  18. for i in @array_process
  19. echo $i
  20. end
  21. for i in @(echo a b c d e)
  22. echo $i
  23. end
  24. echo '# ANCHOR_END: command_substitution'
  25. echo '# ANCHOR: concatenation'
  26. let new_array = [@array @array_process]
  27. for i in @new_array
  28. echo $i
  29. end
  30. echo '# ANCHOR_END: concatenation'
  31. echo '# ANCHOR: array_as_command_args'
  32. echo @array
  33. echo @array_process
  34. echo @new_array
  35. echo '# ANCHOR_END: array_as_command_args'
  36. echo '# ANCHOR: slice_by_id'
  37. let array = [ 1 2 3 ]
  38. echo @array[0]
  39. echo @array[1]
  40. echo @array[2]
  41. echo [ 1 2 3 ][0]
  42. echo [ 1 2 3 ][1]
  43. echo [ 1 2 3 ][2]
  44. echo @(echo 1 2 3)[0]
  45. echo @(echo 1 2 3)[1]
  46. echo @(echo 1 2 3)[2]
  47. echo '# ANCHOR_END: slice_by_id'
  48. echo '# ANCHOR: slice_by_range'
  49. let array = [ 1 2 3 4 5 ]
  50. echo @array[0..1]
  51. echo @array[0...1]
  52. echo @array[..3]
  53. echo @array[3..]
  54. echo @array[..]
  55. echo '# ANCHOR_END: slice_by_range'
  56. echo '# ANCHOR: slice_with_vars'
  57. for index in 0..3
  58. echo $(echo 😉😉😉)[$index]
  59. end
  60. echo '# ANCHOR_END: slice_with_vars'
  61. echo '# ANCHOR: convert_to_string'
  62. let array = [ 1 2 3 4 5 ]
  63. let as_string = @array
  64. echo $as_string
  65. let array = [1 2 3 4 5 6 7 8 9 10]
  66. echo @array[0 1 7..]
  67. echo @array[2 3 5..]
  68. echo @array[5.. 3 2]
  69. echo @array[5..8 1..3 9 2]
  70. echo '# ANCHOR_END: convert_to_string'