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

Proxy Information
Original URL
gemini://alexschroeder.ch/2021-02-02_Skip_the_first_two_files_in_the_shell
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
187.716377 milliseconds
Gemini-to-HTML Time
0.409691 milliseconds

This content has been proxied by September (3851b).