# What's the right way to reuse this one-liner?

I recently came up with the following 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  I needed it because I've got an MP3 player that does not have a shuffle function. It was the only way I could find (in about an hour of trying) to give a suitably random distribution to track names. (At first I used jot, but this program does not update its random seed often enough to produce anything like random results. By the way, if anyone can think of a good way of doing this that actually works, I'm interested to hear about it.) I tried storing it as an alias and got: 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  It just seems like there should be a suitably easy way of storing it in my .bashrc. I'm aware that I could write it to a file and chmod +x it inside my $path with a shebang, but I prefer to use my .bashrc for things wherever possible.

-

How did you define your alias? If you wrote sth like alias bla="for f in *.mp3.... your * might be empty, if you did not escape it, because it is interpreted at evaluatio time of your bash, not at the time it runs. The same will be the case for $f etc. Some other points: Why do you compare two digits (cut -c1-2) to 255? The number will always be smaller than 100. Why do you write $1 - $1 + (1/3)*$1? This is simply ($1)/3. - you're right, and i'm stupid. i tried to define a function originally but i guess i made a typo since it wouldn't work. also, yeah, the math is a bit silly. i thought the max track number was 255 but that's just lame's default max track number. also, i've since moved on to using octave <<< "trace(rand(19,19))" | grep "ans" | sed -e 's/\.//g' | awk '{print$3}' | cut -c3-5 –  ixtmixilix Jun 3 '12 at 19:01