seq 10 > file
(1)变量传入sed如下:
[root@kuaiyun scripts]# sh 1.sh
3
4
5
[root@kuaiyun scripts]# cat 1.sh
#!/bin/bash
a=(1 3 5)
x=${a[1]}
y=${a[2]}
sed -n "${x},${y}p" file
(2)数组传入sed如下:
[root@kuaiyun scripts]# cat 2.sh
#!/bin/bash
a=(1 3 5)
#echo ${a[2]}
#sed -n '2,4p' file
sed -n "${a[1]},${a[2]}p" file
[root@kuaiyun scripts]# sh 2.sh
3
4
5
转载于:https://blog.51cto.com/zlong37/1660203