Reputation: 3015
I'm trying to write a BASH script that will printf
the url of a git remote
into the console, and the remote corresponds to a parameter to the function.
print-remote() {
printf "Remote Url: $(git config --get remote.$1.url)"
}
And I would call it like:
print-remote origin
and it should print out
Remote Url: [email protected]:User/repository.git
But this isn't picking up my $1
, and I'm just getting back
Remote Url:
I feel like I'm missing some syntax.
Upvotes: 1
Views: 305
Reputation: 785621
Try changing your function to:
print-remote() {
printf "Remote Url: %s\n" "$(git config --get remote."$1".url)"
}
Reason being that if output from git
has any %
characters or some other special printf
characters then printf
will try to use them as format parameter.
Or else just use echo
:
print-remote() {
echo "Remote Url: $(git config --get remote."$1".url)"
}
Upvotes: 1