简体   繁体   English

设置Bash脚本的参数

[英]Set Arguments for Bash Script

Hello all I have a bash script I'm using to migrate one artifactory to another. 大家好,我有一个bash脚本,用于将一个工件迁移到另一个工件。

_old_root_url=0
_new_root_url=0
_old_repos=0
_new_repos=0
_include_regex=0
_exclude_regex=0
_username=0
_password=0

while test $# != 0
do
    case "$1" in
    --old-root-url=*)
    old_root_url="${1#--old-root-url=}"
    ;;
    --new-root-url=*)
    new_root_url="${1#--new-root-url=}"
    ;;
    --old-repos=*)
    old_repos="${1#--old-repos=}"
    ;;
    --new-repos=*)
    new_repos="${1#--new-repos=}"
    ;;
    --include-regex=*)
    include_regex="${1#--include-regex=}"
    ;;
    --exclude-regex=*)
    exclude_regex="${1#--exclude-regex=}"
    ;;
    --usernbasame=*)
    username="${1#--username=}"
    ;;
    --password=*)
    password="${1#--password=}"
    ;;
    esac
    shift
done

echo Old Root URL is set to: $old_root_url

exit

I'm having issues setting the arguments on the command line, when I run the script I want to set the 8 argument so that the variables will be set for the rest of the script. 我在运行脚本时在命令行上设置参数时遇到问题,我想设置8参数,以便为脚本的其余部分设置变量。 I have tried: 我努力了:

bash script.txt $old_root_url=test
bash script.txt "$old_root_url=test"
bash script.txt $old_root_url="test"
bash script.txt set --$old_root_url=test

None of these have worked though sadly. 这些都没有可悲的工作。

Pass the arguments like this: 传递这样的参数:

bash script.txt --old_root_url=test

For all of the parameters, follow this pattern, and then it will work. 对于所有参数,请遵循此模式,然后它将起作用。

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

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