简体   繁体   English

如何在bash脚本中传递参数以检查git存储库的状态?

[英]How to pass argument in bash script to check the status of git repository?

I have done following code so far and how can I pass the file path as an argument (insted of setting up in bash script) to bash script and it will check the status of git repository. 到目前为止,我已经完成了以下代码,以及如何将文件路径作为参数(在bash脚本中进行设置)传递给bash脚本,它将检查git存储库的状态。

#!/bin/bash

repos=( 
  "/home/jeff/github/workshop1"
  "/home/jeff/github/workshop2"
  "/home/jeff/github/workshop3"
)

echo ""
echo "Checking" ${#repos[@]} "repositories for status"

for repo in "${repos[@]}"
do
  echo ""
  echo "****** Checking status for" ${repo} "******"
  cd "${repo}"
  git status
  git log
  echo "******************************************"
done

$@ gives you the list of all arguments passed to your script. $@提供给您传递给脚本的所有参数的列表。

Thus, you need to set repos=("$@") . 因此,您需要设置repos=("$@")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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