Quantcast
Channel: Print array elements on separate lines in Bash? - Stack Overflow
Browsing all 9 articles
Browse latest View live

Answer by nicolas for Print array elements on separate lines in Bash?

In zsh one can use the built-in command print -l $path

View Article


Answer by Delyan Lazarov for Print array elements on separate lines in Bash?

You could use a Bash C Style For Loop to do what you want.my_array=(one two three)for ((i=0; i < ${#my_array[@]}; i++ )); do echo "${my_array[$i]}"; doneonetwothree

View Article

Answer by Mario Nigrovic for Print array elements on separate lines in Bash?

I've discovered that you can use eval to avoid using a subshell. Thus:IFS=$'\n' eval 'echo "${my_array[*]}"'

View Article

Answer by 0x00 for Print array elements on separate lines in Bash?

Another useful variant is pipe to tr:echo "${my_array[@]}" | tr '''\n'This looks simple and compact

View Article

Answer by Zombo for Print array elements on separate lines in Bash?

Using for:for each in "${alpha[@]}"do echo "$each"doneUsing history; note this will fail if your values contain !:history -p "${alpha[@]}"Using basename; note this will fail if your values contain...

View Article


Answer by wuxmedia for Print array elements on separate lines in Bash?

I tried the answers here in a giant for...if loop, but didn't get any joy - so I did it like this, maybe messy but did the job: # EXP_LIST2 is iterated # imagine a for loop EXP_LIST="List item"...

View Article

Answer by perreal for Print array elements on separate lines in Bash?

Just quote the argument to echo:(IFS=$'\n'; echo "${my_array[*]}")the sub shell helps restoring the IFS after use

View Article

Answer by Gilles Quénot for Print array elements on separate lines in Bash?

Try doing this :$ printf '%s\n'"${my_array[@]}"The difference between $@ and $*:Unquoted, the results are unspecified. In Bash, both expand to separate argsand then wordsplit and globbed.Quoted, "$@"...

View Article


Print array elements on separate lines in Bash?

How do I print the array element of a Bash array on separate lines? This one works, but surely there is a better way:$ my_array=(one two three)$ for i in ${my_array[@]}; do echo $i;...

View Article

Browsing all 9 articles
Browse latest View live




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>