netdigger
netdigger

Reputation: 3789

Why can't I pass these parameters to my command?

B=master U='[email protected]' curl -u "${U}" "https://bitbucket.org/myteam/pod-dev/raw/${B}/install.bash"

I get asked:

Enter host password for user '':

See, the "U" is missing.

And also curl is performed:

GET /myteam/pod-dev/raw//install.bash HTTP/1.1

Also here, the B is missing (branch)

macOS Sierra 10.12.2

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

Upvotes: 2

Views: 51

Answers (3)

hek2mgl
hek2mgl

Reputation: 157947

Variables assignments like you are using them are part of the command. In your case the shell will try to expand "${A}", "${B}" before they have been actually set - during parsing the command.

You can separate the variable assignments and the actual command by ;:

B=master; U='[email protected]'; curl -u "${U}" "https://bitbucket.org/myteam/pod-dev/raw/${B}/install.bash"

That way they are 3 separate commands.

Upvotes: 4

Bogdan Stoica
Bogdan Stoica

Reputation: 4539

Try like this instead of your command:

export B=master; export U='[email protected]' ; curl -u "$U" "https://bitbucket.org/myteam/pod-dev/raw/$B/install.bash"

Upvotes: -1

pfnuesel
pfnuesel

Reputation: 15300

bash will try to expand the variables first, but you haven't set them at this point. See for example:

$ x=foo echo "$x"
>

$ x=foo; echo "$x"
> foo

Upvotes: 2

Related Questions