我試圖使用sed
將文本插入文件的第一行 。我在sh
腳本中這樣做。將文本插入到shell中的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的stdin。 – neversaint 2009-07-28 08:22:27
另一個問題可能是您使用單引號而不是double,這會阻止環境變量的擴展。因此,你是literaly追加'$ noftags' – 2009-07-28 08:32:55
@DJ:你說得對,謝謝。 – neversaint 2009-07-29 00:53:27