bash/shell 脚本不读取第二个参数 [英] bash/shell script not reading second argument

查看:53
本文介绍了bash/shell 脚本不读取第二个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的脚本,我想以某种方式读取第一个和第二个参数,它不读取第二个参数并抛出错误,说明传递值.

this is simple script which i want to read first and second argument somehow its not reading the second argument and throwing error stating pass the value.

这里是脚本//我想克隆git

Here is the script //I want to clone the git

$cat test.sh

#!/usr/bin/env bash

clone () {
  git clone $2
}

case $1
in
   clone) clone ;;

       *) echo "Invalid Argument passed" ;;
esac

运行脚本

$./test.sh clone https://github.com/sameerxxxxx/test.git/
fatal: You must specify a repository to clone.

usage: git clone [<options>] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting

推荐答案

当你调用你的函数 clone 时,你必须将参数传递给它.

When you call your function clone, you have to pass the arguments to it.

clone() {
    git clone "$1"
}
...
clone) clone "$2";;

请注意,函数的位置参数与脚本本身是分开编号的.

Note that the function's positional parameters are numbered separately from the script itself.

这篇关于bash/shell 脚本不读取第二个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆