LoginSignup
0
0

【shell】シェルスクリプトで外部ファイル読み込み時にコメントアウトに対応させる

Posted at
test.conf
#コメントアウト
hoge1 hoge2 hoge3
foo1 foo2 foo3
#!/bin/sh

# Configファイル
CONF="test.conf"

while read -a line; do
    echo \$line: $line
    echo \${line[*]}: ${line[*]}
    echo \${line[0]}: ${line[0]}
    echo \${line[1]}: ${line[1]}
done < <(grep -v '#' ./$CONF)

応答

$line: hoge1
${line[*]}: hoge1 hoge2 hoge3
${line[0]}: hoge1
${line[1]}: hoge2
$line: foo1
${line[*]}: foo1 foo2 foo3
${line[0]}: foo1
${line[1]}: foo2
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