0

I have an alias for a python script that basically converts some files into another format, I want to be able to remove some intermediate format that this script generates as a post process after running the python script.

My alias to my python script looks like this:

alias convert='python /filepath/convert.py'

I run it like this within the directory containing the files I want to convert:

convert *.RW2

The script converts all .RW2 files into .tiff files but generates an intermediate .dng file which I don't need to keep, it's a temp file.

How would I simply append a delete to the alias? If I modify the alias it seems to interfere with the arguments for the .py script, for example this does not work:

alias convert='python /filepath/convert.py && rm *.dng'

1 Answers1

3

Probably the "cleanest" way to solve this is to modify the convert.py script to clean up after itself.

An alias is a simple text replacement macro - so your example will expand to something like

python /filepath/convert.py && rm *.dng file1.RW2 file2.RW2 file3.RW2 ...

which is obviously going to be incorrect. For anything more complex than a simple text substitution you should use a shell function instead ex.

convert() {
  python /filepath/convert.py "$@" && rm -- *.dng
}

or perhaps

convert() {
  python /filepath/convert.py "$@"
  for f; do 
    rm -- "${f%.*}.dng"
  done
}

(although you may want to choose a different name since there's already an ImageMagick command with the name convert).

See also Aliases - able to pass arguments?

steeldriver
  • 142,475