Passing a string to a bash script via an argument
I'm writing a bash script that, amongst other things, triggers a git commit on a codebase for a specified Drupal 6 site. The script accepts two arguments, the second of which is the commit message for the git commit.
#开发者_如何学Go!/bin/sh
directoryName=${1}
commitMsg=${2}
echo $directoryName
echo $commitMsg
git add .
git commit -vam "The commit message"
The script is called like this:
sh git-bash-test.sh name_of_directory "Custom commit message"
How can I change out "The commit message" for the value stored in $commitMsg?
Simply replace it with "$commitMsg":
git commit -vam "$commitMsg"
sh git-bash-test.sh name_of_directory "$commitMsg"
Note the double-quotes around $commitMsg
.
精彩评论