放入shell脚本时[SED]的奇怪行为

时间:2015-07-23 11:54:26

标签: linux sed

当我这样做时

sed 1s/#text_to_be_replaced#/replacement_string/ filename

然后输出是预期的,但当我把它放在一个shell文件中 并且这样做

lineNumber=1
sed $lineNumbers/#text_to_be_replaced#/replacement_string/ filename

然后它没有按预期工作replacement_stringtext_to_be_replaced上方插入一行。为什么会这样?

1 个答案:

答案 0 :(得分:4)

应该是:

var eventTypes = [["write","write","write","write"],["write","write","read","write"]];
_.each(eventTypes,function(obj){
        gettime(obj);
 });


gettime=function(events){
   var resultArray = [];
   _.each(events,function(event){
      if(event === "read"){
         resultArray.push(makesqlquery(event));
      }else{
         resultArray.push({"time":current_time})
      }
   });
   q.all(resultArray).then(function(finalResult){
        insertIntoPostgreSQL(finalResult);
   });
}

makesqlquery = function(event){
   var deferred = q.defer();
   sql.query("select time from events where eventtype ="+ event,
      function(result,error){
        if(error){
          deferred.reject(error);
        }else{
          deferred.resolve({time:result.time});
        }
    });
   return deferred.promise;
}