Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 the following script:

echo "OUTPUT:"
gcc temp.c
echo "ACTOP"
ulimit -t 1
ulimit -f 1024
ulimit -u 3
./a.out > out.txt

The output I get is

ulimit: 7: Illegal option -u

But if I use ulimit -u 3 in the terminal directly it works. The -t and -f options work fine however.

When I change the shebang to #!/bin/bash it works, but now it refuses to execute code unless the no. of allowed processes > 132. Anything less than ulimit -u 132 does not allow execution. In the terminal directly I was able to work with ulimit -u 3.

share|improve this question
What does your temp.c code do? – qbi Feb 5 '13 at 13:12

ulimit is a shell builtin, not a program:

$ type ulimit
ulimit is a shell builtin

What it means is that ulimit may not work the same way with every shell.

The default shell in Ubuntu is Bash, and it is the shell you use from the terminal.

However in your script you are using sh, which (by default) is provided by is Dash, a shell similar, but different from Bash. Compare:

$ bash
$ ulimit -u
$ dash
$ ulimit -u
dash: 1: ulimit: Illegal option -u

There are at least two solutions for your problem:

  1. change your shebang from #!/bin/sh to #!/bin/bash;
  2. use -p instead of -u.

I would recommend the first solution, because Bash has many more features than Dash. The drawback is that Bash is slower, but it your script is not performance-critical, this won't be a problem.

For more information about the difference between Bash's ulimit and Dash's ulimit, you can see man bash and man dash, then perform a search typing /ulimit. Additionally, Bash provides a help builtin that you can use as an alternative to the man page.

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.