Chinaunix

标题: 变量传入sed? [打印本页]

作者: zl624867243    时间: 2015-05-11 12:31
标题: 变量传入sed?
有下面文件:
$sudo cat file
ttt
yyy
jjj
bbb
ccc
ddd

我想在第二行下面插入变成这个样子。
ttt
aa    cc=(dd)       ee
yyy
jjj
bbb
ccc
ddd

我自己写了一个脚本不行,(其中user是变量,我要将变量传入sed)不知道该怎么改。

#!/bin/bash
user=aa
eval sed  "2i\$user    cc=(dd)       ee" file


作者: 关阴月飞    时间: 2015-05-11 12:33
把eval去掉:
  1. sed  "2i$user    cc=(dd)       ee"  file
复制代码

作者: stupid_lee    时间: 2015-05-11 12:34
  1. sed  "2i$user    cc=(dd)       ee" file
复制代码

作者: zl624867243    时间: 2015-05-11 12:39
好的 感谢。。。。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2