日: 2023年2月3日

  • [: 1: unexpected operator

    github actions で [: 1: unexpected operator というエラーが出た時の対処法を紹介。

    原因はshell が POSIX に準拠していないため起こる。

    POSIX に準拠している構文かどうかは checkbashisms コマンドで確認することができる。

     checkbashisms hogehoge.sh
    possible bashism in hogehoge.sh line 16 (should be 'b = a'):
        if [ $exist == 0 ] ; then
    

    この構文が問題であることがわかった

    上記の通りアドバイスをくれる。

     if [ $exist == 0 ] ; then
    

    今回はアドバイス通りではなく

    if [ $exist -eq 0 ] ; then

    と変更して対処した。