简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM