problem creating bash loop through svn list output
Preston Kutzner
shizzlecash at gmail.com
Tue Nov 25 17:47:28 UTC 2008
On Nov 25, 2008, at 10:31 AM, Bram Kuijper wrote:
> Hi all,
>
> I hope this question is not too specific for a ubuntu mailing list,
> but
> it is about simple bash shell scripting. I cannot get bash to properly
> loop through the output of a svn list command, like this:
>
> svnlist=`svn list file:///myrepository/directory`
>
> for i in "$svnlist"; do
> echo "$i";
> echo "nextline";
> done;
You need to treat $svnlist as an array, as opposed to just a string
variable.
svnlist=(`svn list file:///myrepository/directory`)
for i in ${svnlist[@]}; do
echo "$i"
echo "nextline"
done
You might need to change your $IFS variable (internal field
separator). By default it is set to use whitespace as field
separators. This is fine if *NONE* of your filenames have spaces in
them. To be on the safe side, I would change your script to look like
this:
OLDIFS="${IFS}"
IFS=$'\x0A'
svnlist=(`svn list file:///myrepository/directory`)
for i in ${svnlist[@]}; do
echo "$i"
echo "nextline"
done
IFS="${OLDIFS}"
unset OLDIFS
What output are you attempting to achieve with this script? As it
stands it will look something like this:
<filename>
nextline
<filename>
nextline
<filename>
nextline
etc... where <filename> is a file name from that directory and
nextline is the literal text "nextline"
>
>
> However, this does not work at all, the variable $svnlist is not
> splitted into separate items, but just passed as a whole list to $i,
> so
> the output looks like:
>
> file1
> file2
> file2
> nextline
>
> instead of the desired output:
> file1
> nextline
> file2
> nextline
> file3
> nextline
>
>
> Why does bash looping appear to seamlessly work with commands like
> ls(),
> but does it choke on svn list?
>
> thanks in advance,
>
> Bram kuijper
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
More information about the ubuntu-users
mailing list