Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 used to execute the command:

sudo -u elasticsearch -s "ulimit -Hn"

and it was returning the value of ulimit -Hn as seen by user elasticsearch until I tried it on Ubuntu 11.10. There it returns:

/bin/bash: ulimit -Hn: command not found

I tried a few different commands, and when I use an argument I always get "command not found":

$ sudo -u elasticsearch -s "ls all.sh"
/bin/bash: ls all.sh: command not found

Any ideas on how can I execute a command that requires arguments through sudo?


share|improve this question
why the -s? Just keep the normal shell and use it to execute commands. Such as sudo -u elasticsearch ls all.sh. If elasticsearch has an unusable default shell, use -s bash before the actual command. – glglgl Nov 12 '11 at 10:21
up vote 12 down vote accepted

You need to remove the double-quotes. It is trying to run a command called "ulimit -Hn" as a single command, spaces and all. -s needs to be the last sudo option on the sudo command line, and all following arguments are passed to $SHELL -c to execute.

sudo -u elasticsearch -s ulimit -Hn

I guess the way -s is processed has changed, as the current way allows you to pass arguments with spaces to $SHELL by escaping them on the command line:

$ touch '/tmp/foo bar'
$ sudo -s rm '/tmp/foo bar'

The old method of argument handling would split that '/tmp/foo bar' argument into two, breaking the command.

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.