I am trying in my linux (Xubuntu) console to make the git commit message in my chain of commands a variable so I can more easily execute my chain of commands.
Instead of this where I habe to edit inside the command:
b cucumber && git add . && git commit -m "my commit message" && git push && b cap staging deploy && b cap production deploy
I would like to use a variable. Something like:
$MSG="my new workflow"b cucumber && git add . && git commit -m $MSG && git push && b cap staging deploy && b cap production deploy
Since I am a super bad at this things I would like to check back with someone who knows. Is the syntactically correct way of doing this?
Romain Valeri
22.8k3 gold badges52 silver badges76 bronze badges
-
I didn't remember having answered to this years ago. Sorry not to have found it earlier, let's close this question as duplicate.Romain Valeri– Romain Valeri2025年09月10日 14:42:46 +00:00Commented Sep 10, 2025 at 14:42
1 Answer 1
The typical way of solving this is to declare an ad-hoc bash function in an alias where you can use numbered parameters (1,ドル 2,ドル ...), like:
git config --global alias.somename '!f() { b cucumber && git add . && git commit -m "1ドル" && git push && b cap staging deploy && b cap production deploy; }; f'
# then you can do
git somename "your message here will replace the 1ドル"
answered Sep 10, 2025 at 9:44
Romain Valeri
22.8k3 gold badges52 silver badges76 bronze badges
Sign up to request clarification or add additional context in comments.
7 Comments
Julian
your answer looks good @Romain Valeri. Could you elaborate more on the syntax please a little? Specifically: For what is the f needed? So I could do: git config --global alias.deploy '!f() { b cucumber && git add . && git commit -m "1ドル" && git push && b cap staging deploy && b cap production deploy }; f' Then I can do git deploy "my awesome commit" is that right? That would be awesome!
Romain Valeri
The
f stands for the ad-hoc function name, it is declared with f() { body } and it is called at the end with the simple f. And yes your renamed version looks fine :-)Julian
I did: git config --global alias.deploy '!f() { b cucumber && git add . && git commit -m "1ドル" && git push && b cap staging deploy && b cap production deploy }; f' and git deploy "test 2" results in => f() { b cucumber && git add . && git commit -m "1ドル" && git push && b cap staging deploy && b cap production deploy }; f: 1: Syntax error: end of file unexpected (expecting "}") What is wrong?
Romain Valeri
@Julian Hmm...that's odd. I didn't ask before but: where are you executing the commands? I assumed bash but is it Windows cmd?
Romain Valeri
Oh! No I see it now, we need a final
; missing after the last command inside the ad-hoc bash function, my bad! Edited my answer. Sorry for this.Julian
it seems to work. At least the cucumber test are running :-) Thanks a ton for support!
Julian
no. Linux console