我正在执行一个命令,该命令将我文件夹中的文件列表作为输入。所以我正在执行
cat <(for i in ls *chr*.txt; do echo $i; done)
Run Code Online (Sandbox Code Playgroud)
但是,我不想包含此列表中的第一个条目。换句话说,我想跳过迭代 1,所以我只有 n-1 个*chr*.txt文件。我该怎么做呢?
根本不要ls在这里使用。将您的文件放入一个数组中,您可以从第二个元素开始扩展该数组。
files=( *chr*.txt )
printf '%s\n' "${files[@]:1}"
Run Code Online (Sandbox Code Playgroud)
在不支持数组的基线 POSIX shell 中,您可以"$@"出于相同的目的使用,并shift删除第一项:
set -- *chr*.txt # put all names matching the pattern in $1/$2/...
shift # remove $1, putting $2 in its place, moving $3 to $2, etc
printf '%s\n' "$@" # print each item from our argument list on a separate line.
Run Code Online (Sandbox Code Playgroud)