Bash

命令替換為 bash 腳本 $1 值

  • July 6, 2015

我有這個簡單的腳本,可以更改我的 apache2 網站的權限

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

我的目錄中有兩個.shshell 腳本html/

/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*

我已經在兩個網站上執行了腳本。我正在嘗試在其他站點上使用命令替換:

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

或者

/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.

但是這兩個命令都沒有改變所有網站的權限。我對編輯腳本不感興趣。我可以在這種情況下使用命令替換嗎?

由於您不想編輯腳本:

for f in $(ls -I "*.sh"); do ./permissions_setup.sh $f; done;

引用自:https://serverfault.com/questions/703663