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 1 year has passed since last update.

In POSIX sh, array references are undefined.とシェルスクリプトの警告で怒られた

Posted at

該当のチェック

怒られたコード

#!/bin/sh

for item in "${files[@]}"; do
    echo "$item"
done

修正方針その1

あんまりshebangとか意識したことなかったですが、bashの機能なので警告が出たということでした。

#!/bin/bash

for item in "${files[@]}"; do
    echo "$item"
done

修正方針その2

shebangを変えずに別の書き方で再現するならこうなると思います

#!/bin/sh

echo "$diffFiles" | while read -r line; do
    echo "$line"
done
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?