I'm creating a script where I clone git repositories. I want my script to print "Cloning OK" when the cloning is successful and "Cloning FAILED" when it fails and ignore all command output for both occasions. This is the code I'm using:
(git clone -q "$url" && echo "$url: Cloning OK") || echo "$url: Cloning FAILED" >&2
The problem is that for successful cloning the command stays quiet but for unsuccessful cloning it doesn't. How can I make it quiet for both occasions?
Thanks in advance
You have to silence the command by sending standard output and standard error to somewhere other than the terminal. This is easiest achieved by sending both output streams to /dev/null:
(git clone -q "$url" >/dev/null 2>&1 && …
Please note that silencing this command will make your script harder to debug.