【发布时间】:2015-11-12 00:52:47
【问题描述】:
我有许多文件,它们的名称中有一条有用的信息,我想将它们提取为变量并在后续步骤中使用。文件名的结构是 samplename_usefulbit_junk。我正在尝试使用文件名(样本名)的可预测部分来遍历这些文件,将整个名称存储在一个变量中,并使用sed 来提取有用的位。这没用。
samples="sample1 sample2 sample3"
for i in $samples; do
filename="$(find ./$FILE_DIR -maxdepth 1 -name '$(i)*' -printf '%f\n')"
usefulbit="$(find ./$FILE_DIR -maxdepth 1 -name '$(i)*' -printf '%f\n' | sed 's/.*samplename//g' | sed 's/junk.*//g')"
(More steps using $usefulbit or $(usefulbit) or ${usefulbit} or something)
done
find ./$FILE_DIR -maxdepth 1 -name 'sample1*' -printf '%f\n' 和 find ./$FILE_DIR -maxdepth 1 -name "sample1*" -printf '%f\n' 都可以工作,但是括号、花括号或单引号、双引号或反引号的组合无法使循环正常工作。这哪里出错了?
【问题讨论】:
标签: bash variables for-loop find