How to run echo command as root?

Asked by TechnoGeek on 2007-07-08

After installing Cinelerra it erred with a following:

void MWindow::init_shm(): WARING: /proc/sys/kernel/shmmax is 0x2000000, which is to low.
  Before running Cinelerra do the following as root:
  echo "0x7fffffff" > /proc/sys/kernal/shmmax

I am new to Ubuntu and need help on how to get this done.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
2007-07-08
Last reply:
2007-07-08
Jacob Godserv (fun2program8) said : #1

There's a difficulty here. If you just run "sudo echo "0x7fffffff" > /proc/sys/kernal/shmmax" then it'll run the echo command in root, but the "> /proc/sys/kernal/shmmax" bit will not.

Just run:
sudo su
echo "0x7fffffff" > /proc/sys/kernal/shmmax

To quit from root after running the above, run:
exit

Here's why the above works (if you care to read).

Bash (which is your terminal, basically) manages ">" and "|" stuff, not software. sudo is actually software that gives you a new root terminal within your terminal. So, when you run "sudo echo "0x7fffffff" > /proc/sys/kernal/shmmax", all sudo sees is "echo "0x7fffffff"". The ">" part bash takes care of.

So, the only solution is to get the entire command in a root terminal. There's two ways of doing this (as far as I know, but there's probably more). First, there's the handy "sudo su" command. In this case, sudo runs su. su is normally disabled, but when you run it with sudo, it suddenly springs to life, and it gives you a root terminal for as long as you like, until you quit it with an "exit" command.

It is VITAL you UNDERSTAND what you are doing BEFORE you run ANY command in "sudo". You've probably been told this before, but I want to make sure. If you aren't careful, you'll be pulling that install disk out again, or you'll be debugging issues for hours on end.

So now I have a question: do you understand what that echo command will do? Obviously you want to understand what you are doing before you run anything in root. :)

There's another way to do this. You can run:
sudo sh -c "echo '0x7fffffff' > /proc/sys/kernal/shmmax"

This one's a bit more interesting. sudo runs a new SH terminal (remember, Bash is a terminal, so SH is just a more basic terminal). The -c part tells sh to run a command that you give it instead of asking for one (like Bash does) and then quit automatically without waiting for you to say "exit". The command you gave it to run was "echo '0x7fffffff' > /proc/sys/kernal/shmmax". The reason it is enclosed in quotes like that is because if you don't, Bash will see the ">" bit and again separate it from echo. Notice the quotes within the quotes are different - they are single quotes, because if I used double quotes, it would think I've ended the previous double-quote, etc.

Which brings up an interesting point about this particular solution - if you used sh -c, you can only have one layer of quotes inside the -c part, whereas in the sudo su command, you can have all two layers of 'em (double and single). However, the trade-off is, with sh -c, you can run root commands within Bash scripts, if or when you learn about those too.

So, two ways to do this. Which way would I recommend? The first way with "sudo su", if you are doing it personally, the second "sudo sh -c" way if a Bash script is doing it. With either solution, you are using a root terminal, so it is VITAL you UNDERSTAND what you are doing BEFORE you run ANY command in "sudo". (Just making sure you get that bit. :)

Can you help with this problem?

Provide an answer of your own, or ask TechnoGeek for more information if necessary.

To post a message you must log in.