0

私は csh スクリプトを初めて使用します。スクリプトを作成するのはこれが初めてです。コードは次のとおりです。

#!/bin/csh

#arg1 path 
#arg2 condition 
#arg3 number of files 
#arg4-argN name of files

set i=0 
while ( $i < $3 ) 
        if ($2 == 0) then 
                cp /remote/$1/$($i+4) $1/new.$( $i+4 ) 
                p4 add $1/new.$($i+4) 
        else 
                p4 edit $1/new.$($i+4) 
                cp /remote/$1/$($i+4) $1/new.$($i+4)
        endif 
        $i = $i+1 
end 

しかし、ここで私はエラーを取得しています。変数名が不正です。いくつかのチュートリアルを読みましたが、関連するものは何もありません。助けてください。前もってThx。

4

2 に答える 2

0

最初の行でフラグ -v および -x を使用して、スクリプトの動作を確認できます

#!/bin/csh -vx

問題は、カウンター変数に 4 を追加しようとする部分で発生します

$($i+4)

csh はそのように追加できません。一時変数を使用してカウンターに 4 を追加し、その変数をすべての呼び出しで使用します。

@ i = 0 
while ( $i < $3 ) 
        @ iplusfour = $i + 4
        if ($2 == 0) then 
                cp /remote/$1/$($i+4) $1/new.$iplusfour 
                p4 add $1/new.$iplusfour 
        else 
                p4 edit $1/new.$iplusfour 
                cp /remote/$1/$iplusfour $1/new.$iplusfour 
        endif 
        @i = $i + 1 
end 

ウィリアムズのコメントも取り入れました。

于 2017-04-05T06:24:36.687 に答える