chop string(arguments passed by user)

52 Views Asked by At

suppose the user passed 5 arguments($1 $2 $3 $4 $5), how do I cut off the first two arguments($1 $2) and I only want the last 3 arguments

awk '{print $3,$4,$5} < $@' what if I don't know how many arguments passed but I do not want the first two arguments

I can not use shift since I also need info from $2, what should I do then?

I ran into this problem when tar files in bash script when the user might use regular expressions like *.txt and the shell will automatically convert that into file1.txt file2.txt (suppose there are only two .txt files)

1

There are 1 best solutions below

2
hek2mgl On

There is a syntax for this:

#!/bin/bash

# note: indexing starts at 0

# 0: script name
# 1: arg 1
# 2: arg 2

# this will skip the script name, arg1 and arg2
echo "${@:3}"