user321627
user321627

Reputation: 2564

How to pass in a read bash variable in linux and sent it as a message in git commit?

I would like to automate the git commit function and be able to read in a message like as follows in bash:

echo -n "Enter message and press [ENTER]: " 
read mess

cd /my/dir
git add *
git commit -m "$(mess)"

However, it tells me in bash that in line 6: mess: command not found. Is there something I am doing wrong?

Upvotes: 1

Views: 244

Answers (1)

oxr463
oxr463

Reputation: 1891

In your script, $(mess) denotes a sub-shell which executes the command mess; which isn't a real command.

Replace the parenthesis with brackets.

echo -n "Enter message and press [ENTER]: " 
read mess

cd /my/dir
git add *
git commit -m "${mess}"

Update

Per the bash manual, under command substitution it states the following,

Command substitution allows the output of a command to replace the command name. There are two forms: $(command) or `command` Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.

Upvotes: 4

Related Questions