bash
そのコマンドを含むシェルスクリプトを作成しましたが、while
端末でそのコマンドを使用してスクリプトを実行すると、source
構文エラーメッセージが表示されます。
source
端末で環境変数を設定する必要があるため、使用する必要がありますが、いいえsource
。
echo $shell
提供:シェルは与えられた対話式出力では/bin/csh
ありません。ps -p $$
CMD : tcsh
スクリプトは次のとおりです。
#! /bin/bash
i=1
while read line
do
echo "$line $i"
echo
i=$((i+1))
done < seed.txt
エラーは次のとおりです。
i=1: Command not found.
while: Expression Syntax.
ベストアンサー1
このエラー?
$ tcsh
tcsh> source while.sh
i=1: Command not found.
while: Expression Syntax.
tcsh> exit
Csh/tcsh は POSIX sh または Bash とは異なるシェルです。 (t)cshでsh構文を使用してスクリプトを実行しようとすると機能しません。
source
端末で環境変数を設定する必要があるため、使用する必要がありますが、いいえsource
。
実際にエクスポートした環境変数にしますsetenv
。
tcsh> cat hello.sh
echo "hello, $name"
tcsh> bash hello.sh
hello,
tcsh> setenv name vikas
tcsh> bash hello.sh
hello, vikas