Skip to content

Commit 5af3298

Browse files
committed
Array slice for $@
1 parent cfee4f3 commit 5af3298

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

book.org

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,23 @@
196196
#+begin_src bash
197197
a=(a b c d e f g)
198198
echo "${a[@]:1}" # tail of array
199-
echo "${a[@]:1:2}" # from position 1, take 2 elements
199+
echo "${a[@]:1:2}" # from that, take 2 elements
200200
#+end_src
201201

202+
Don't ask me why, but when the array is =$@=, it seems that it
203+
behaves a bit differently (would be great to know why):
204+
205+
#+begin_src bash
206+
a=(a b c d e f g)
207+
foo() {
208+
echo "${@:2}" # tail of array
209+
echo "${@:2:2}" # from that, take 2 elements
210+
}
211+
foo a b c d
212+
foo "${a[@]}"
213+
#+end_src
214+
215+
202216
** Read lines from file
203217
The =read= command we used just above is part of the usual idiom to
204218
read a file line by line.

0 commit comments

Comments
 (0)