[root@VM_163_107 /opt/xyrpg/rpgserver/log/54198]# cat tar_log.sh#!/bin/shdata=`date +%Y%m%d%H%M`echo -n "input dir:"read dircd $dirpwdls -clecho -n "input end line num:"read numls -c|head -$num|xargs zip $dir$data.zipsz $dir$data.ziprm -rf $dir$data.zip
ls -c|sed -n '1,$nump'
$num 和p之间暂未处理好
处理方法
报错原因是sed 用变量需要用“”
修改后,正常可行。
简单两种方式
[root@VM_163_107 /opt/xyrpg/rpgserver/log/54198]# cat tar_log.sh#!/bin/shdata=`date +%Y%m%d%H%M`echo -n "input dir:"read dircd $dirpwdls -clecho -n "input end line num:"read num#ls -c|head -$num|xargs zip $dir$data.zipls -c|sed -n "1,${num}p"|xargs zip $dir$data.zipsz $dir$data.ziprm -rf $dir$data.zip