假设用户传递了5个参数($1
$2
$3
$4
$5
),我如何切断前两个参数($1
$2
),我只想要最后3个参数
awk '{print $3,$4,$5} < $@'
如果我不知道传递了多少个参数但我不想要前两个参数
我不能使用shift,因为我也需要$2的信息,我该怎么办?
我遇到了这个问题,当tar文件在bash脚本中,当用户可能使用正则表达式,如*.txt
和shell将自动转换成file1.txt
file2.txt
(假设只有两个.txt
文件)
这有一个语法:
#!/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}"