Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written a bash script from which i execute it from the root. I want to execute a particular command in a user account rather than root account.So how to execute that command in a user account and not in root account.For example i want to execute this command

echo 'user_pref("toolkit.networkmanager.disable", true);' >> ~/.mozilla/firefox/*.default/prefs.js` 

in a user account say karthick how to execute it?

share|improve this question
In the case of appending a file, you could just append it as root, and the file will still be owned by the user. Hence, you don't really need either sudo or su in this specific case. – Egil Apr 24 '11 at 10:25
up vote 2 down vote accepted
sudo -u karthick 'echo \'user_pref("toolkit.networkmanager.disable", true);\' >> ~/.mozilla/firefox/*.default/prefs.js`'

Most likely your problem can be solved more elegantly by some other means. Perhaps if you described that we could help solve the larger problem.

share|improve this answer
su karthick -c "echo \'user_pref(\"toolkit.networkmanager.disable\", true);\' >> ~/.mozilla/firefox/*.default/prefs.js"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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