简体   繁体   中英

Git status command remote out from bash-Script and email it

Is it possible to do an "git status" and output the result into an echo? Or send the output as email?

I guess the email-thing is no problem but I stuck doing an echo.

What I got

clear 
output="$(git status)"
echo output

But... yeah, it won't work and I searched certain examples but they lead always ino a git status if,. and i need the output:( Is there way simple way to get this done

And, how to handle if this should be called on a remote system:

ssh ${SSHUSER}@${LIVE_HOST} << EOF
...
EOF

The echo is useless ; all you need is

git status

If you genuinely need to store the output in a variable as well as print it, try

output=$(git status)
echo "$output"

To run it remotely, you don't need a here document at all;

ssh "${SSHUSER}@${LIVE_HOST}" git status

and again, if you need to store that in a variable, that would be

output=$(ssh "${SSHUSER}@${LIVE_HOST}" git status)
echo "$output"

If you really want to store the command in a here document, that's possible too:

ssh "${SSHUSER}@${LIVE_HOST}" <<\:
git status
:

or in Bash you could use a "here string":

ssh "${SSHUSER}@${LIVE_HOST}" <<<'git status'

If you want to send the result as email, a common arrangement is

git status | mail -s "Status report from xyz" you@example.com

but the mail command is poorly standardized, so you may have to consult a manual page or Google for a bit.

An echo "$output" would work better

echo ouput would just print output .

I just tried:

$ o=$(git status 2>&1); echo "$o"
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

It does not working because you missed the variables syntax.

Rewrite your code as follow:

clear 
output="$(git status)"
echo "$output"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM