

下のコードを実際に動した時に

[code]

    203100B
    203101K
    .
    .
    .
    
[/code]

となって欲しいのですが全部最後に付く文字が `A` になってしまいます。  
どこがおかしいのか教えていただけますでしょうか。

[code]

    #!/usr/bin/awk -f
    BEGIN{
    
        for(i = 0;i <= 40; i++){
            zyu[i]=int(i/10)
                iti[i]=i%10
                check[i]=((33+zyu[i]*3+iti[i]*2)%11)%10
    
                if (check[i]=0) printf("2031%02d%1s\n",i,"B")
                else if (check[i]=1) printf("2031%02d%1s\n",i,"A")
                else if (check[i]=2) printf("2031%02d%1s\n",i,"K")
                else if (check[i]=3) printf("2031%02d%1s\n",i,"J")
                else if (check[i]=4) printf("2031%02d%1s\n",i,"H")
                else if (check[i]=5) printf("2031%02d%1s\n",i,"G")
                else if (check[i]=6) printf("2031%02d%1s\n",i,"F")
                else if (check[i]=7) printf("2031%02d%1s\n",i,"E")
                else if (check[i]=8) printf("2031%02d%1s\n",i,"D")
                else if (check[i]=9) printf("2031%02d%1s\n",i,"C")
        }
    }
    
[/code]


CC BY-SA 4.0
2022-01-17T08:16:31.427
85757
2022-01-17T08:25:28.410
2022-01-17T08:25:28.410
3060
50943
question
awk
awkの出力が思うようにいかない


`if` 文 (および `else`) で `=` が一つのため、比較ではなく **代入になっているのが原因** だと思います。

値の比較を行うには `==` を使用してください。

**修正例 (抜粋):**

[code]

                if (check[i]==0) printf("2031%02d%1s\n",i,"B")
                else if (check[i]==1) printf("2031%02d%1s\n",i,"A")
                else if (check[i]==2) printf("2031%02d%1s\n",i,"K")
                else if (check[i]==3) printf("2031%02d%1s\n",i,"J")
                else if (check[i]==4) printf("2031%02d%1s\n",i,"H")
                else if (check[i]==5) printf("2031%02d%1s\n",i,"G")
                else if (check[i]==6) printf("2031%02d%1s\n",i,"F")
                else if (check[i]==7) printf("2031%02d%1s\n",i,"E")
                else if (check[i]==8) printf("2031%02d%1s\n",i,"D")
                else if (check[i]==9) printf("2031%02d%1s\n",i,"C")
    
[/code]


CC BY-SA 4.0
2022-01-17T08:24:27.357
85758
2022-01-17T08:24:27.357
3060
85757
answer