Joseph John
Joseph John

Reputation: 520

How can I pass all the filenames in a directory as an argument to a command in Bash?

I'm using Subliminal (a tool to find subtitles for any given media file) to get the subtitles for a bunch of TV series episodes, and right now, I'm doing it manually, for every single episode. It's a tedious process. Instead, I'd like to automate it using Bash.

Me not being a Bash-ninja, tried this first:

for i in /dir/*.avi; do subliminal -l en -- "$i"; done;

But obviously, that didn't work.

subliminal also accepts multiple filenames as parameters, so the following works as well:

subliminal -l en -- file1.avi file2.avi ... filen.avi

But it's quite a lot of work to manually type and tab-complete every file name. I figured there'd be some easier way to accomplish this? Maybe using xargs, but I'm not sure.

What are your ideas?

Upvotes: 0

Views: 3090

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798516

Wildcards expand before the command is run.

subliminal -l en -- file*.avi

Upvotes: 2

Related Questions