tags:

views:

48

answers:

3

let's say my script takes filenames starting from $3

e.g.

archive u 2342 a.txt b.png c.html d.js
archive u 2222 a.txt b.png

I want to zip all the files listed starting from $3 How can I do that?

thanks

+6  A: 

The bash command shift is your friend.

The script example.sh

#!/bin/bash
shift 3
echo $*

called with example.sh 1 2 3 4 5 will output 4 5.

tangens
See http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html
Jon Rodriguez
+6  A: 
zip archivename.zip "${@:3}"
Gordon Davisson
this generalizes better than using shift
Augie
+3  A: 
FIRST=$1
shift

SECOND=$1
shift

echo $FIRST
echo $SECOND
echo tar cf archive.tar "$@"

Input:

./test.sh 1 2 3 4 5

Output:

1
2
tar cf archive.tar 3 4 5
Alex Howansky