以 tar.bz2 为例:
$ cat test
Alice comes upon a mushroom and sitting on it is a blue Caterpillar smoking a
hookah. The Caterpillar questions Alice and she admits to her current identity
crisis, compounded by her inability to remember a poem. Before crawling away,
the caterpillar tells Alice that one side of the mushroom will make her taller
and the other side will make her shorter. She breaks off two pieces from the
mushroom. One side makes her shrink smaller than ever, while another causes
her neck to grow high into the trees, where a pigeon mistakes her for a serpent.
With some effort, Alice brings herself back to her normal height. She stumbles
upon a small estate and uses the mushroom to reach a more appropriate height.
$ tar jcf test.tbz2 test
写入 shell 脚本,并将数据放入 exit 0 之后:
$ lines=`echo '1,p\nq' | vim -e test.tbz2 | wc -l`
$ cat > 1.sh << EOF
> #!/bin/bash
> start_line=7
> end_line=$((7+$lines-1))
> sed -n \$start_line','\$end_line'p' \$0 | head -c -1 | bzcat
> exit 0
>
> EOF
$ cat test.tar.bz2 >> 1.sh
$ echo "\n" >> 1.sh
$ chmod +x 1.sh
$ rm test.tbz2
$ ./1.sh
网友评论