Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash脚本中将N个文件作为参数传递(也在随机位置)_Bash_Command Line Arguments - Fatal编程技术网

在bash脚本中将N个文件作为参数传递(也在随机位置)

在bash脚本中将N个文件作为参数传递(也在随机位置),bash,command-line-arguments,Bash,Command Line Arguments,我正在写一个脚本来详细说明许多文本文件 我需要将N个文本文件传递给我的bash脚本 脚本调用如下所示: :~$ ./bristat [-u user] [-p] [-m] file1.log...fileN.log 脚本详细说明了日志文件的以下参数-u-m-p args-u-m-p是可选的(我可以使用任何、任何或所有这些args调用脚本) file1.log…fileN.log是执行所必需的(0

我正在写一个脚本来详细说明许多文本文件

我需要将N个文本文件传递给我的bash脚本

脚本调用如下所示:

:~$ ./bristat [-u user] [-p] [-m] file1.log...fileN.log
脚本详细说明了日志文件的以下参数-u-m-p

  • args
    -u-m-p
    是可选的(我可以使用任何、任何或所有这些args调用脚本)
  • file1.log…fileN.log
    是执行所必需的(0shift

    在你得到你的论点之后

    shift $(( OPTIND-1 ))
    while [ -f $1 ] 
    do 
       #do whatever you want with the filename in $1.
       shift
    done
    

    这个好答案可能会有帮助:谢谢。我还有一个疑问。请看我的编辑。我可以把这段代码放在脚本中的什么地方?在我的
    之前或里面,而getopts$params OPT;
    ?见鬼,我甚至没有看到代码底部的最后一个移位。就在最底部。关于你的“任何顺序的参数”…它需要有某种结构。特别是如果在某个地方有一个项目的“列表”。换句话说,不要这样做。
    shift $(( OPTIND-1 ))
    while [ -f $1 ] 
    do 
       #do whatever you want with the filename in $1.
       shift
    done