57-56-遍历文件夹内全部文件脚本

2020年11月29日 作者 刘剑
#!/bin/bash

oneRandom()
{
    m=$[ $RANDOM % 10 ] 
}

threeRandom()
{
    oneRandom
    a=$m
    oneRandom
    b=$[ $m * 10 ]
    oneRandom
    c=$[ $m * 100 ]
    s=$[ $a + $b +$c ]
    echo $s
    return $?
}

# ------------------- 公共函数 -----------------------

# 防止文件名有空格, for循环后一个文件变成多个文件
IFS=$(echo -en "\n\b"); 

# 给文件全部重命名, 添加三位随机数前缀
for file in `ls *.mp3`
do

 echo $file
 sj=`threeRandom`

 mv "$file" "$sj-$file"

done