0

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:

  1. $MSG="my new workflow"
  2. 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
asked Sep 10, 2025 at 9:36
1
  • I didn't remember having answered to this years ago. Sorry not to have found it earlier, let's close this question as duplicate. Commented Sep 10, 2025 at 14:42

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

7 Comments

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!
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 :-)
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?
@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?
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.
it seems to work. At least the cucumber test are running :-) Thanks a ton for support!
no. Linux console

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.