Bash variable in {$var} brackets reads as %7Bvar%7D?

-1

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?

user1776193

Posted 2013-03-26T02:38:03.843

Reputation: 67

Answers

2

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.

Dennis

Posted 2013-03-26T02:38:03.843

Reputation: 42 934

Wow... Thank you for pointing that out. Been a long day! Would upvote you if I could. – user1776193 – 2013-03-26T02:53:53.800

Actually, now I am having this problem. See comment below. – user1776193 – 2013-03-26T03:07:55.470

Nevermind, I guess I can't comment because I don't have enough reputation. Sorry for this hard to read question: – user1776193 – 2013-03-26T03:09:23.193

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 – 2013-03-26T03:09:52.853

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 – 2013-03-26T03:18:19.837

You were right about both things. The for loop works perfectly now. Thank you so much! You saved me a huge headache! Edit: I will keep that in mind for future superuser etiquette. – user1776193 – 2013-03-26T03:21:53.373

Thanks, I'm glad you reminded me! Should have left it as answered in the first place, since you did answer my question. :) – user1776193 – 2013-03-26T04:03:44.220