I'm writing a bash script. I have a series of pipes working to get all the branches on a git repository:git ls-remote $1 'refs/heads/*' \  | rev \  | cut -d'/' -f1 \  | rev \  | if [ -z $2 ]      then        echo {}      else        echo {} > $2    fiCurrently the if statement part of this doesn't work properly. What do I replace {} with to make this work?
Pipe into if statement?
bash;shell script;pipe
To copy standard input to standard output, use cat, not echo.git ls-remote $1 'refs/heads/*' |sed 's~.*/~~' |if [ -z $2 ]  then    cat  else    cat > $2fiNotice also the proper use of quotes and the placement of the pipes so you can avoid the backslashes. The use of sed is a very minor optimization but I also find it clearer than the double rev around a cut (provided you grok regex). You could also use awk -F/ '{ print $NF }' (but then that requires you to grok Awk).You could avoid the cat by doing this instead;${2+exec >$2}git ls-remote $1 | sed 's~.*/~~'(The failure if you pass in an empty string as the second argument should at least be more explicit, if not necessarily more helpful, than with [ -z, which fails to distinguish between an unset and an empty value.)