通过指示文件扩展名扩展包含前缀的变量,该前缀是包含所有文件的目录的名称
Expand a variable containing a prefix that is a name of the directory containing all files by indicate the extension of files
我有一个包含 Fortran .f90
文件的目录 temp_sources
。
我尝试扩展通配符 *.f90
以打印所有 Fortran90 文件,以 temp_sources
目录为前缀。
总而言之,我想存储在一个变量中:
temp_sources/file1.f90
temp_sources/file2.f90
temp_sources/file3.f90
...
temp_sources/file11.f90
我尝试在一个带有两个参数的脚本中执行此操作(第一个用于目录,即 temp_sources
,第二个用于 *.90
)
dir1="$dir1"
# Adding a slash for directory if not present
[[ "$dir1" != */ ]] && dir1=$dir1"/"
# Try to expand the files *.f90
files=( "$dir1${@:2:$#-2}" )
# Try to print the list with directory name as prefix
echo "$files"
但仅打印(最后回显):temp_sources/*.f90
它不会将 .f90
文件列表扩展到 temp_sources
目录作为前缀。
我不知道如何用这个目录名得到这个列表。
试试
files=( "$dir1"${@:2:$#-2} )
您希望 shell 处理 *
的扩展,因此不应将其括在括号中。
我有一个包含 Fortran .f90
文件的目录 temp_sources
。
我尝试扩展通配符 *.f90
以打印所有 Fortran90 文件,以 temp_sources
目录为前缀。
总而言之,我想存储在一个变量中:
temp_sources/file1.f90
temp_sources/file2.f90
temp_sources/file3.f90
...
temp_sources/file11.f90
我尝试在一个带有两个参数的脚本中执行此操作(第一个用于目录,即 temp_sources
,第二个用于 *.90
)
dir1="$dir1"
# Adding a slash for directory if not present
[[ "$dir1" != */ ]] && dir1=$dir1"/"
# Try to expand the files *.f90
files=( "$dir1${@:2:$#-2}" )
# Try to print the list with directory name as prefix
echo "$files"
但仅打印(最后回显):temp_sources/*.f90
它不会将 .f90
文件列表扩展到 temp_sources
目录作为前缀。
我不知道如何用这个目录名得到这个列表。
试试
files=( "$dir1"${@:2:$#-2} )
您希望 shell 处理 *
的扩展,因此不应将其括在括号中。