Hacker News new | past | comments | ask | show | jobs | submit login

There are a couple of ways you can do it. Don't do this with `ls` though; there are better ways to get that info in scripts.

    # Loops over lines, in a subshell
    prints_lines | while read -r line; do
      some_command "$line"
    done

    # Loops over lines, in the current shell
    while read -r line; do
      some_command "$line"
    done < <(prints_lines)

    # If for some reason you really want a for loop
    oldIFS=$IFS
    IFS=$'\n' lines=($(prints_lines))
    IFS=$oldIFS
    for line in "${lines[@]}"; do
      some_command "$line"
    done



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: