Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to do a for loop, but Cygwin does not understand the {$var} syntax.

My command:

for f in 'svn ls repo_path'; path/{$f}trunk/path; done

Error svn: E170000: URL path/%7Bvar%7Dtrunk/path doesn't exist

The string should come out to be: path/var/trunk/path

How can I make the variable + string concatenation work?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The syntax is ${f}, not {$f}.

If you really want path/var/trunk/path, you can simply use path/$f/trunk/path. This works whether $f end with a slash or not. Bash doesn't mind a double slash.

Also, be careful with parsing the output of ls.

Actually, now I am having this problem: for f in 'svn ls repo_path'; path/${f}trunk/path; done

Comes out as: path/var/%0Dtrunk/path

%0D is a carriage return character. A newline in Windows is \r\n, not the expected \n.

Try setting

IFS=$' \t\r\n'

before the for loop.

share|improve this answer
    
Wow... Thank you for pointing that out. Been a long day! Would upvote you if I could. –  user1776193 Mar 26 '13 at 2:53
    
Actually, now I am having this problem. See comment below. –  user1776193 Mar 26 '13 at 3:07
    
Nevermind, I guess I can't comment because I don't have enough reputation. Sorry for this hard to read question: –  user1776193 Mar 26 '13 at 3:09
    
Actually, now I am having this problem: for f in 'svn ls repo_path'; path/${f}trunk/path; done Comes out as: path/var/%0Dtrunk/path (f is "var/" not "var", so path/$f/trunk/path would not work) NOTICE: The random %0D –  user1776193 Mar 26 '13 at 3:09
    
By the way, you can edit your question to incorporate additional information. Just click the edit link below the question itself. You should only answer your own question if you actually want to post a solution. –  Dennis Mar 26 '13 at 3:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.