2016-11-01 8 views
0

こんにちは私は、あるartifactoryを別のものに移行するために使用しているbashスクリプトを持っています。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 

私は変数は、スクリプトの残りのために設定されるように、8引数を設定するスクリプトを実行するとき、私は、コマンドラインに引数を設定する問題を抱えています。私が試してみました:これらの

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 

なし悲しげにかかわらず、働いていません。 、すべてのパラメータについては

bash script.txt --old_root_url=test 

をこのパターンに従ってください、そして、それは動作します:

+1

'bash script.txt --old_root_url = test'?あなたのスクリプトは、実際に設定されているパラメータの名前として、 '_old_root_url'または' old_root_url'のいずれかで解決する必要があるようです。 – chepner

+0

@Maccauleyあなたはこのスクリプトを書いていますか?非常にシンプルだからです: 'bash bashargs.sh --old-root-url = value works' –

答えて

0

は、このような引数を渡します。

関連する問題