Last Updated: February 25, 2016
·
606
· theatlasroom

Handling arguments in bash alias

Short snippet showing how to handle n arguments in a bash alias.

The example accepts n filenames, checks if the files exist in haml within the directory and attempts to compile the haml code to html.


haml_args(){
    for file in "$@"    
    do
        if [ ! -f "$file.haml" ];
        then
            echo "Error: $file.haml does not exist"
        else
            echo "Compiling $file.haml .........."
            haml $file.haml $file.html
            echo "Finished"
        fi
    done
} 
alias hamlc=haml_args

If you have a better way to do this, please enlighten me!