How to print array elements on a separate line in Bash
In this post we will give you information about How to print array elements on a separate line in Bash. Hear we will give you detail about How to print array elements on a separate line in BashAnd how to use it also give you demo for it if it is necessary.
we will learn how to print the array elements on a separate line in Bash.
Consider, we have the following prices array in Bash:
prices=(10 20 30)
Printing the array elements
To print the array elements on a separate line, we can use the printf command with the %s format specifier and newline character n in Bash.
Here is an example:
prices=(10 20 30)printf '%sn' "${prices[@]}"
Output:
102030
@$ expands the each element in the array as a separate argument.
%s is a format specifier for a string that adds a placeholder to the array element.
n adds the line break after each element in an array.
Hope this code and post will helped you for implement How to print array elements on a separate line in Bash. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs