0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CentOSで動いてたシェルスクリプトがUbuntuで動かない

Posted at

CentOS用のシェルスクリプトを「まあsh準拠なら動くやろ」と思って気軽に動かしたが、CentOSは/bin/shが/bin/bashにシンボリックリンクされており、シバンを#!/bin/shにしてもbash(のsh互換モード)が動いてる。

一方でUbuntuは6.10以降shをdash(Debian Almquist shell)にシンボリックリンクしているそうだ。dashはashのDebian派生らしく、POSIXに準拠している。

先述のsh互換モードのbashというのがけっこう曲者でbashの拡張機能も一部動く。UbuntuとCentOSで互換の仕方が違うので単純なshでは互換性がむしろ低い状態になっている。体感Ubuntu->CentOSよりCentOS->Ubuntuの時に問題になる。具体的にはこういう構文が動かなくなる。

function test{
    ...
}

解決方法としてはシバンをbashに書きかえるか、sudo dpkg-reconfigure dashを実行して/bin/shのシンボリックリンクをbashに変えるか、単に一発実行すればいいなら./xxxx.shじゃなくてbash xxxx.shにする。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?