sed
を使用してファイルの最初の行にテキストを挿入しようとしました。 私はこれをsh
スクリプトの中で行います。シェルスクリプト内でSedを使ってファイルにテキストを挿入
しかし、なぜsed実行の行でハングするのですか?
#! /bin/sh
# Command to execute
# ./mybashcode.sh test.nbq
nbqfile=$1
nbqbase=$(basename $nbqfile nbq)
taglistfiletemp="${nbqbase}taglist_temp"
taglistfile="${nbqbase}taglist"
./myccode $nbqfile |
sort |
uniq -c |
awk '{print $2}' > $taglistfiletemp
noftags=$(wc -l $taglistfiletemp | awk '{print $1}')
echo $noftags
# We want to append output of noftags
# to the first line of taglistfile
sed '1i\
$noftags' > $taglistfile
# why it hangs here
# the content of taglistfile is NIL
@MA:ありがとうございます。確かに私はsedのための標準を見逃した。 – neversaint
別の問題は、doubleの代わりに一重引用符を使用していて、環境変数の拡張を妨げている可能性があります。したがって、あなたは文字通り '$ noftags'を追加しています –
@DJ:そうです、ありがとうございます。 – neversaint