2021-02-02 Skip the first two files in the shell

On my Windows box, when I’m not using Emacs, I often listen to music using Cygwin and mpg123.exe... Yikes, but also yay‽

I have a folder full of mp3 files and want to start playback with the second file but all I know is this: `mpg321 *.mp3`. Is there some bash thing to shift that list of expansions by one, two or three?

This works:

IFS=


\n'
mpg123 $(ls Music/Rachmaninov/All-night\ Vigil/*.mp3|tail +3)

Thanks, @Whidou, @specter, @craigmaloney.

@Whidou

@specter

@craigmaloney

This also works, using arrays:

readarray -d '' files < <(printf '%s\0' Music/Rachmaninov/All-night\ Vigil/*.mp3)
mpg123 "${files[@]:9}"

Thanks, @notclacke.

@notclacke

I finally discovered my initial attempt with `set -- *.mp3; shift; mpg123 "$*"` didn’t work. I need to use `"$@"` instead!

set -- Giana\ My\ Invisible\ Friend/*.mp3
shift 2
mpg123 "$@"

Thanks, @etam.

@etam

Various looping constructs where also suggested:

i=0; for f in *; do i=$((i+1)); if [[ $i -lt 2 ]]; then continue; fi; mpg123 "$f"; done

That one has the benefit of being as easy to understand as the ls/tail construct above! Thanks, @dredmorbius.

@dredmorbius

​#Shell ​#Programming