-1

What is the purpose of the %\ in the following URL?

http://controller:8774/v2/%\(tenant_id\)s

I'm very new with Linux but i understand that the forward slash \ is often used as an escape character. I also know that the % symbol is used as an escape character in URL encoding. Not sure how the combination of %\ works?

It is used to create an OpenStack nova API. The exact command is

openstack endpoint create --region RegionOne \ compute public http://controller:8774/v2/%\(tenant_id\)s

Any guidance would be greatly appreciated.

mrahma04
  • 109
  • 1
  • 6
  • What is the context for this? Is this typed in a command line or a shell script, or somewhere else? (By intuition, `%\ ` is nothing; `\(` and `\)` are escapes for parentheses that would otherwise be taken to have special meaning to shell). – Amadan Nov 24 '15 at 02:31
  • Where did u found such URL? % is followed by a number usually – Newbie Nov 24 '15 at 02:32

1 Answers1

0

As I surmised, the URL is "http://controller:8774/v2/%(tenant_id)s". Quoted, it works like it is supposed to:

$ echo "http://controller:8774/v2/%(tenant_id)s"
http://controller:8774/v2/%(tenant_id)s

$ echo 'http://controller:8774/v2/%(tenant_id)s'
http://controller:8774/v2/%(tenant_id)s

Escaped works as well:

$ echo http://controller:8774/v2/%\(tenant_id\)s
http://controller:8774/v2/%(tenant_id)s

But if you don't do something to remove the special meaning from the parentheses, bash will complain:

$ echo http://controller:8774/v2/%(tenant_id)s
-bash: syntax error near unexpected token `('

This is because bash uses parentheses to group commands into subprocesses:

$ (echo bear && echo aardvark) | sort
aardvark
bear

and thus an open parenthesis can't come anywhere where you can't start a command.

Meanwhile, the meaning of %(...) is specific to openstack; I believe it is a variable that will be replaced before the URL is used as an actual URL; so it is more of an URL template than an actual URL.

Amadan
  • 191,408
  • 23
  • 240
  • 301