【发布时间】:2016-05-12 20:00:19
【问题描述】:
我正在使用 bash shell。我正在编写一个脚本,我想捕获在参数 #5 之后(包括参数 #5)传递给我的脚本的可变数量的参数。到目前为止,我有这个……
#!/bin/bash
…
declare -a attachments
attachments=( "$5" )
但我想不通的是如何编写“附件”行来包含参数 #5 以及随后的任何参数。所以在下面的例子中
sh my_script.sh arg1 arg2 arg3 arg4 “my_file1.csv” “my_file2.csv”
我希望附件由“my_file1.csv”和“my_file2.csv”组成,而在本例中……
sh my_script.sh arg1 arg2 arg3 arg4 “my_file1.csv” “my_file2.csv” “my_file3.csv”
我希望附件包含“my_file1.csv”、“my_file2.csv”和“my_file3.csv”。
【问题讨论】:
-
首先不要使用那些愚蠢的引号,其次获取前4个args然后
shift 4和attachments=( "$@" )
标签: bash shell command-line-arguments