Sample Header Ad - 728x90

Why does printing an array with @ using printf in bash only print the first element?

2 votes
1 answer
291 views
I have an array snapshots=(1 2 3 4) When I run printf "${snapshots[*]}\n" It prints as expected 1 2 3 4 But when I run printf "${snapshots[@]}\n" It just prints 1 without a newline. My understanding is that accessing an array with @ is supposed to expand the array so each element is on a newline but it does not appear to do this with printf while it does do this with echo. Why is this?
Asked by geckels1 (173 rep)
Apr 12, 2024, 08:41 PM
Last activity: Jun 17, 2024, 07:25 AM