Bash loop for a string

    • Bash loop for a string

      Hello,

      I am trying to figure out how to loop through an output line by line. For example, when I run the following command at the command line: svn status

      I get the following output:
      ? homeFolder.A.bak
      A homeFolder.bak
      ? homeFolder/Location.pm
      M LOG.pm


      However, when I put this in a loop:

      Source Code

      1. for toCommit in $(svn status)
      2. do
      3. echo "line is : $toCommit"
      4. done


      I get this output:
      line is : ?
      line is : homeFolder.A.bak
      line is : A
      line is : homeFolder.bak
      line is : ?
      line is : homeFolder/Location.pm
      line is : M
      line is : LOG.pm

      I don't want it to treat spaces as variable separators. I want the output to be like the following:
      line is : ? homeFolder.A.bak
      line is : A homeFolder.bak
      line is : ? homeFolder/Location.pm
      line is : M LOG.pm

      Any help would be greatly appreciated.

      Thanks,
      Frank
    • sixstringartist wrote:

      Try this:

      Shell-Script

      1. while read line; do
      2. echo "$line"
      3. done < $(svn status)


      Did I mention that I was using bash? The above works great if using sh or ksh. Unfortunately, with BASH, I receive the following error:

      line 115: 0: ambiguous redirect

      I appreciate your help. Unfortunately, I need a way to do this in bash.

      Thanks,
      Frank