1

I have this simple script which changes permissions on my apache2 websites

/var/www/html# cat permissions_setup.sh 
chown -R root $1
chgrp -R www-data $1
chmod -R 750 $1
chmod g+s $1

I have two .sh shell scripts in my html/ directory

/var/www/html# ll
total 40
drwxr-xr-x 8 root root     4096 Jul  5 16:45 ./
drwxr-xr-x 4 root root     4096 Jun 13 18:37 ../
drwxr-s--- 5 root www-data 4096 Jun  6 18:17 foo.com/
drwxr-s--- 5 root www-data 4096 Jun 13 18:52 bar.org/
drwxr-xr-x 5 root root     4096 Jun 13 18:13 barfoo.com/
-rwxr-xr-x 1 root root       67 Jul  5 16:44 permissions_setup.sh*
drwxr-xr-x 5 root root     4096 Jun 13 18:42 foobar.com/
-rwx------ 1 root root     1163 Jun 13 18:41 website_add.sh*

I have already ran the script on two websites. I am trying to use command substitution on the other sites as such:

/var/www/html# ./permissions_setup.sh $(ls -I "*.sh")

or

/var/www/html# ls -I "*.sh" $(./permissions_setup.sh)
chown: missing operand after ‘root’
Try 'chown --help' for more information.
chgrp: missing operand after ‘www-data’
Try 'chgrp --help' for more information.
chmod: missing operand after ‘750’
Try 'chmod --help' for more information.
chmod: missing operand after ‘g+s’
Try 'chmod --help' for more information.

But neither commands changed the permissions on all the websites. I am not interested in editing the script. Am I able to use command substitution in this scenario?

2

Since you don't want to edit the script:

for f in $(ls -I "*.sh"); do ./permissions_setup.sh $f; done;
  • 1
    There's an award for this... – dawud Jul 6 '15 at 13:05
  • I don't think that applies here as the -I "*.sh" is used to exclude files and the double quotes keep it from being expanded by the shell. – Brian Jul 7 '15 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.