简体   繁体   中英

Set Arguments for Bash Script

Hello all I have a bash script I'm using to migrate one artifactory to another.

_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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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