在bash中洗牌文件列表
对于目录中的每个文件,我想执行一个python程序在bash中洗牌文件列表,bash,random,shuffle,Bash,Random,Shuffle,对于目录中的每个文件,我想执行一个python程序 #!/bin/bash for file in mp3/* ; do if [[ "$file" == *.wav ]]; then python wav.py --file $file elif [[ "$file" == *mp3 ]]; then python mp3.py --file $file fi done 如何修改
#!/bin/bash
for file in mp3/* ; do
if [[ "$file" == *.wav ]]; then
python wav.py --file $file
elif [[ "$file" == *mp3 ]]; then
python mp3.py --file $file
fi
done
如何修改此bash脚本,使文件以随机顺序获取
一种方法可能是(递归地)将文件从目录加载到列表中,然后首先洗牌列表。遗憾的是,我不太擅长bash脚本编写。使用
sort-R
将洗牌文件列表:
#!/bin/bash
ls mp3/* |sort -R |while read file; do
if [[ "$file" == *.wav ]]; then
python wav.py --file $file
elif [[ "$file" == *mp3 ]]; then
python mp3.py --file $file
fi
done
多么令人沮丧。。。我正在键入答案,问题结束了。您必须在“$file”周围使用引号,并且