linux - 如何在 linux 中传入读取的 bash 变量并将其作为消息发送到 git commit 中?

标签 linux bash git

我想自动化 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/

相关文章:

具有不同结构的 Git fork

python - 如何让网络服务器响应本地网络之外的请求?

python - 我如何从 Ap cisco 获取客户数量并将其保存在变量中?

linux - 进程如何在/usr/lib下的文件夹中找到共享库

c - 如何在 C 中处理管道中的 n 个命令?

Bash: 'sort' 如何对路径进行排序?

bash - 重用 Vim 终端缓冲区

git - Git .ssh 的默认路径是什么?

bash - Spyder 无法启动 : spyder: command not found

git - 修补程序的正确方法是什么?