Thorsten
Thorsten

Reputation: 3461

Emacs: shell commands on multiple files - how to refer to the actual file in the script?

Lets say I have a group of (text) files in Emacs, either by

Then I want to call a shell script on all the files in the group. Easy enough. But in the script, I have a command that takes a file as argument like this:

foo(file)

Since the looping over the group of files is conveniently done by Emacs, I would need a kind of shell variable that refers to the file that is processed at the moment, something like:

$file = {the file that is processed at the moment}

foo($file)

But how do I get a reference to the processed file? I would probably need the absolute path.

Thanks for any help.

Upvotes: 0

Views: 110

Answers (1)

pmielke
pmielke

Reputation: 431

It looks like you are doing operations on multiple files in the shell. I would recommend saving the list of filenames into a file and then use the command xargs to operate on the files.

So for example to run doit.sh on all the filenames saved in the file filelist the command would be:

$ xargs -n 1 doit.sh < filelist

In the file doit.sh the current file is $1.

Upvotes: 1

Related Questions