Server Fault is a question and answer site for system and network administrators. 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

In a bash script I would like to execute multiple commands while keeping a file locked with setlock. Setlock however only supports the following usage:

setlock [-NnXx] [lock file] [command]

Is there a way to wrap multiple commands together besides using a separated script?

share|improve this question
up vote 4 down vote accepted

You can use sh as a command, enabling you to use &&, ; or || as usual to chain multiple commands as desired inside single quotes.

For example to run command1 followed by command2 (if the first exits without errors):

setlock lockfile sh -c 'command1 && command2'
share|improve this answer
Thanks Eduardo, I really appreciate it. – John Jun 3 '11 at 8:35

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.