1

How do I make an alias in .bashrc with sub-commands?

Right now I have:

alias pngc="for file in \`find \$1 -name \"*.png\"\`; do pngcrush -brute \"\$file\" temp.png; mv -f temp.png \$file; done"

If I enter this in a shell, the alias is registered correctly and I can run it correctly. However, if I add this to .bashrc, (parts of) it runs at login, which I know because it hangs for a huge amount of time, probably because it's find-ing in my entire home directory.

(Not a duplicate of this or that)

Edits based on comments:

Attempt:

alias pngc="for file in ./*.png; do pngcrush -brute \"\$file\" temp.png; mv -f temp.png \$file; done"

Could not find file: ./*.png
Could not find file: temp.png

(temp is the current directory)

Attempt:

alias pngc="for file in ./*.png; do [[ -f \"\$i\" ]] || continue; pngcrush -brute \"\$file\" temp.png; mv -f temp.png \$file; done"

Does nothing!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.