#!/bin/bash
sudo echo "export foo" >> /root/bashrc

じゃダメなのか?