0

I am trying to modify my git remote repo address and I got confused over pipe (|).
What is the difference between the two and why the first option doesn't work?

# Doesn't work
git remote get-url origin | sed 's/old/new/' | git remote set-url origin

Works

git remote set-url origin $(git remote get-url origin | sed 's/old/new/')

itaied
  • 103

1 Answers1

2

The answer is that git remote set-url needs its final argument (the actual URL) on the command line, not as its standard input. Your first line (the one with the pipe) tries to feed the URL as standard input.

Your second line, OTOH, almost¹ correctly interpolates the URL as a command line argument (the final one) to the top-level command.


¹ you forgot the double quotes around the command substitution to prevent the unwanted split+glob here.

q.undertow
  • 556
  • 2
  • 10