Anastasios Andronidis
Anastasios Andronidis

Reputation: 6720

execute commands with curly brackets on bash

I would like to know why the following command is not working in Bash and how it's possible to make it run:

/etc/init.d/{httpd,nscd} status

Thanks

Upvotes: 0

Views: 222

Answers (2)

user3657561
user3657561

Reputation: 11

That does not work because it only expands the the path. Try this.

$ echo  /etc/init.d/{httpd,nscd} status

$ /etc/init.d/httpd /etc/init.d/nscd status

Upvotes: 1

devnull
devnull

Reputation: 123448

Your command doesn't work because it'd execute:

/etc/init.d/httpd /etc/init.d/nscd status

One way of achieving what you want would be to make use of a loop:

for util in /etc/init.d/{httpd,nscd} ; do
  ${util} status
done

Upvotes: 6

Related Questions