Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write value1 || value2 in shell?

Tags:

shell

I would make a simple script in shell and put a default value in case the user enters nothing. Here is my script:

git add -A
git commit -m "checkpoint commit"
git push

I would make something like

git add -A
git commit -m ($1 || "checkpoint commit")
git push
like image 422
Webwoman Avatar asked May 24 '26 20:05

Webwoman


1 Answers

You can use

git commit -m "${1:-checkpoint commit}"

If $1 is set, ${1:-checkpoint commit} will expand to the value of $1.

If $1 is not set, it will expand to whatever is after the :- (ie "checkpoint commit" in this example).

like image 104
Alain Merigot Avatar answered May 26 '26 14:05

Alain Merigot