重复使用这一行的正确方法是什么?

重复使用这一行的正确方法是什么?

我最近想出了以下一句话:

for f in *.mp3; do sha1sum $f | sed -r 's/[a-z]//g' | cut -c1-2 | awk '{ print ($1 >= 255) ? $1 - $1 + (1/3)*$1 : $1 }' | xargs -i id3v2 -T {} $f; done

我需要它是因为我有一个没有随机播放功能的 MP3 播放器。这是我能找到的唯一方法(在大约一个小时的尝试中)给出适当的随机分布来跟踪名称。 (起初我使用了jot,但是这个程序更新其随机种子的频率不足以产生类似随机结果的东西。顺便说一句,如果有人能想到一种真正有效的好方法,我很想听听它。)

我尝试将其存储为别名并得到:

awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                   ^ syntax error
awk: cmd. line:1: { print ( >= 255) ?  -  + (1/3)* :  }
awk: cmd. line:1:                                  ^ syntax error

似乎应该有一种适当简单的方法将其存储在我的.bashrc.

我知道我可以将其写入文件并使用 shebang 将chmod +x其写入我的文件中,但我更喜欢尽可能使用 my 。$path.bashrc

答案1

如果您确实不想将其放在自己的文件中,则应该使用 bash功能,不是一个别名

你是如何定义你的别名的?如果你写了像alias bla="for f in *.mp3....你这样的东西*,如果你没有转义它,它可能是空的,因为它是在 bash 的评估时解释的,而不是在它运行时解释的。$f等的情况也是如此。

其他几点:为什么要将两个数字 ( cut -c1-2) 与 255 进行比较?该数字始终小于 100。为什么要写$1 - $1 + (1/3)*$1?这只是 ($1)/3。

相关内容