LoginSignup
2
1

More than 3 years have passed since last update.

bashで「Syntax error: "(" unexpected」が表示される

Posted at

配列処理のあるシェルスクリプトでエラーが発生

これ系のエラーはしばらく経つと忘れてしまうため調べたことの備忘録です。
他の環境で作成したシェルスクリプトが問題ないはずなのにエラーが発生。

Syntax error: "(" unexpected

環境はUbuntuでした。
シバンはbashでしてたのですがなぜかエラーになりました。
いちおう確認したらbashじゃなくてdashにつながりってます。

ls -l /bin/sh
lrwxrwxrwx 1 root 4 Apr 23 15:40 /bin/sh -> dash

bashを探すとあったのでシバンを変更したら大丈夫でした。

which bash
/usr/bin/bash

調べた結果

どうやらdashというのは配列が使えないシェルらしいのです。
ashというAlpine Linuxのコマンドをベースにしているようです。
だからdashという名前なんですね。
これを使いたい場合はwhileでループ処理するみたいでした。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1