2
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?

More than 5 years have passed since last update.

POSIX sh 準拠のスクリプトを書くために shellcheck を導入した

2
Last updated at Posted at 2018-07-25

できごと

実装したshell scriptが、docker環境(alpine linux)で動作しなかった

原因

  • alpine linuxのshellはash
  • POSIX標準ではない記法をスクリプトに書いてしまったため、ashで動作しなかった

対策

shellcheck というshell用のlintツールがあるので、事前に確認しよう

使い方

homebrew でインストール

.shell-session
$ brew install shellcheck

以下のコードで動作確認してみる

test.sh
# !/bin/sh

if [[ ${HOGE} =~ fuga ]]; then
  echo "aaa"
fi
.shell-session
$ shellcheck test.sh

In test.sh line 3:
if [[ ${HOGE} =~ fuga ]]; then
   ^-- SC2039: In POSIX sh, [[ ]] is undefined.

無事、[[ はPOSIX標準記法ではないと怒られました

2
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
2
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?