我试图使用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