bashスクリプトがtcshで起動したときにコマンドが機能しない間?

bashスクリプトがtcshで起動したときにコマンドが機能しない間?

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

おすすめ記事