I want use git pull
in my shell script, it print 'Already up-to-date.', but I don't want it be printed. I want to save these message to a variable. How to do this? Thanks very much!
update:
➜ gitvar=$(git checkout alpha)
Already on 'alpha'
➜ echo $gitvar
M _gg.sh
M _posts/2018-10-22-about.md
I want to save "Already on 'alpha'" to variable "gitvar". The $(...) don't. Does this have anything to do with zsh?
update:
I'm sorry. I didn't know stdout and stderr before. Thank you for telling me this.
The answer to the question is that the print of the command may be stdout, or it may be stderr.
1 output=$(command) # stdout only; stderr remains uncaptured
2 output=$(command 2>&1) # both stdout and stderr will be captured