LoginSignup
0
0

More than 3 years have passed since last update.

bash scriptでCOLUMNSという名前の変数を使ってはいけない

Posted at

COLUMNS変数はbashの予約変数なので、意図しないタイミングで変更されてスクリプト実行が失敗する可能性がある。

以下のスクリプトを実行すると、mkdirの後でCOLUMNS変数が上書きされているのがわかる。

#!/bin/bash

COLUMNS="a,b,c"
echo ${COLUMNS}
mkdir -p /tmp/t
echo ${COLUMNS}
$ bash test.sh
a,b,c
204

その他の予約変数は Bash Guide for Beginners | 3.2.4. Reserved variables に記載がある。
LINESなどは同じ間違いをしてしまいそう。

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