How to get first 5 chars of a git commit hash id and store it in a variable in bash?
Using --short
option:
$ git rev-parse --short=5 HEAD
90752
$ x=$(git rev-parse --short=5 HEAD)
$ printf '%s\n' "$x"
90752
The cut utility should do what you want.
$ x=$(git rev-parse HEAD | cut -c1-5) && echo $x
Why one line?