我想自动化 git 提交功能,并能够在 bash 中读取如下消息:
echo -n "Enter message and press [ENTER]: "
read mess
cd /my/dir
git add *
git commit -m "$(mess)"
但是,它在 bash 中告诉我,在 第 6 行:mess: command not found。
是我做错了什么吗?
最佳答案
在您的脚本中,$(mess)
表示一个子 shell,它执行命令 mess
;这不是真正的命令。
用方括号替换圆括号。
echo -n "Enter message and press [ENTER]: "
read mess
cd /my/dir
git add *
git commit -m "${mess}"
更新
根据 bash manual ,在命令替换下,它声明如下,
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.
关于linux - 如何在 linux 中传入读取的 bash 变量并将其作为消息发送到 git commit 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56999467/