Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    newline separator in bash for loop

    When I try to iterate over some filenames (with whitespaces in them) in bash, I came up with the following:

    export IFS=$(echo -e "\n")
    for i in $(ls -1); do echo $i; done;

    however, this does not seperate the files at all; it stores all the filenames in one variable $i.

    When I change IFS to:
    export IFS=$(echo -e "\n\b")
    it does give the desirable response.

    Why is the '\b' necessary? What needs to be 'backspaced' ?

  2. #2
    I think the \b prevents the newline character from getting ignored by the shell, but you can instead try this cleaner alternative:


  3. #3
    That seems like a much cleaner way indeed. Thanks for the help!

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts