I am working on function that will resize and optimize all images in the directory with single command.

So far I created this function

function prepareimages() {

    # Resize Images
    for img in *.jpg; do
        convert -resize $1\! "$img" "$img"

    # Optimize Images
    jpegoptim *.jpg

The idea is that I can use


Then I tried to save the alias in .bashrc file, but dont know how to save it

I know you can save normal commands like

alias home="ssh root@"

But is there way to save function as alias ?

alias prepareimages = prepareimages();

This doesnt work.

  • What do you mean by "doesnt work"? Also, function calls in the shell don't use parentheses.
    – choroba
    Apr 25, 2019 at 17:04

1 Answer 1


You don't need an alias, you can save a function directly. Just save the definition into your .bashrc file.

To invoke it, use prepareimages 400x300, i.e. no parenhteses. You can use single or double quotes, but as there's no special character, they aren't needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.