で変数から読み取るにはどうすればよいwhile read line
ですか?
例えば:
the_list=$(..code..)
while read line
do
echo $line
done < $the_list
上記のコードを使用すると、エラーが発生します。
./copy.sh: line 25: $the_list: ambiguous redirect
で変数から読み取るにはどうすればよいwhile read line
ですか?
例えば:
the_list=$(..code..)
while read line
do
echo $line
done < $the_list
上記のコードを使用すると、エラーが発生します。
./copy.sh: line 25: $the_list: ambiguous redirect
あなたは書ける:
while IFS= read -r line
do
echo "$line"
done <<< "$the_list"
Bash Reference Manualの §3.6.7「Here Strings」を参照してください。
(また、変数の内容をいじりすぎないように、自由に二重引用符を追加し、 に and を追加しまし-r
た。)IFS=
read
変数を他に使用しない場合は、変数を使用しなくても構いません。
while read line ; do
echo $line
done < <( ... code ... )
You can just use
your_code | while read line;
do
echo $line
done
if you don't mind the while loop executing in a subshell (any variables you modify won't be visible in the parent after the done
).
スクリプト ファイルは Linux モードである必要があります。以前は dos モードでした。を使って変えました dos2unix filename
。
例えば:
dos2unix sshcopy.sh
今ではうまくいきます。