anarchy
anarchy

Reputation: 5174

How to use a directory of filenames as arguments in a linux shell command

I want to run the following command in linux, python3 pythonScript.py filename1 filename2 filename3 filename4 filenameN.....

If I wanted to run the filenames as a list I would do python3 pythonScript.py $(< filenamelist.txt) where filename list.txt contains filename1 filename2 filename3 filename4 filenameN.... in each line.

Is there a way I can run this command without generating the list and just feed the directory of filenames directly into the command?

Upvotes: 0

Views: 157

Answers (2)

Ron
Ron

Reputation: 6551

You can use xargs:

find somefolder -maxdepth 1 -print0 |xargs -0 python3 pythonScript.py

Upvotes: 2

Jetchisel
Jetchisel

Reputation: 7781

Try brace expansion.

python3 pythonscript.y filename{1..10}
  • If you need to set the N limit to a variable, then you need a loop, because brace expansion happens before variable does in bash.

Upvotes: 1

Related Questions