This script will take a c file (named main.c), compile it into a main.o file, convert this to a .elf file and then convert the .elf to a .hex and finally flash the chip with this hex using avrdude.
First install avrdude by opening terminal and entering :
sudo apt-get install avrdude
Then install avr-gcc:
sudo apt-get install gcc-avr
Here is the bash script:
#!/bin/bash avr-gcc -g -Os -mmcu=atmega1281 -c main.c && avr-gcc -g -mmcu=atmega1281 -o main.elf main.o && avr-objcopy -j .text -j .data -O ihex main.elf out.hex && avrdude -p atmega1281 -c jtag2 -P usb -U lfuse:w:0xc2:m -U hfuse:w:0xb9:m -U efuse:w:0xff:m -U flash:w:out.hex