Qual é o caminho certo para reutilizar este one-liner?

1

Recentemente, criei o seguinte one-liner:

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

Eu precisava disso porque eu tenho um tocador de MP3 que não tem uma função de shuffle. Foi a única maneira que encontrei (em cerca de uma hora de tentativas) de distribuir adequadamente aleatoriamente os nomes das faixas. (No começo eu usei jot , mas este programa não atualiza sua semente aleatória com frequência suficiente para produzir algo como resultados aleatórios. A propósito, se alguém puder pensar em uma boa maneira de fazer isso que realmente funcione, estou interessado para ouvir sobre isso.)

Eu tentei armazená-lo como um alias e recebi:

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

Parece que deve haver uma maneira fácil de armazená-lo no meu .bashrc .

Estou ciente de que posso escrevê-lo em um arquivo e chmod +x dentro de meu $path com um shebang, mas prefiro usar meu .bashrc para as coisas sempre que possível.

    
por ixtmixilix 03.06.2012 / 18:47

1 resposta

4

Se você realmente não quiser ter isso em seu próprio arquivo, use uma função bash , não um alias .

Como você definiu seu alias? Se você escreveu algo como alias bla="for f in *.mp3.... your * pode estar vazio, se você não escapou, porque ele é interpretado no tempo de avaliação do seu bash, não no momento em que é executado. O mesmo será o caso de $f etc.

Alguns outros pontos: Por que você compara dois dígitos ( cut -c1-2 ) a 255? O número será sempre menor que 100. Por que você escreve $1 - $1 + (1/3)*$1 ? Isso é simplesmente ($ 1) / 3.

    
por 03.06.2012 / 20:15

Tags