Упростите командные строки в скрипте

У меня есть этот сценарий, и я хотел бы его упростить. Любая помощь приветствуется:

#!/bin/ash
chmod 775 /path/to/directory
chown -R http:http /path/to/directory
cd /path/to/directory
find . -type d -exec chmod 775 {} \; ; find . -type f -exec chmod 664 {} \;

chmod 775 /path/to/directory1
chown -R http:http /path/to/directory1
cd /path/to/directory1
find . -type d -exec chmod 775 {} \; ; find . -type f -exec chmod 664 {} \;

chmod 775 /path/to/directory2
chown -R http:http /path/to/directory2
cd /path/to/directory2
find . -type d -exec chmod 775 {} \; ; find . -type f -exec chmod 664 {} \;

Спасибо.

0
11.03.2017, 00:33
1 ответ
#!/bin/ash
for i in \
         '/path/to/directory'  \
         '/path/to/directory1' \
         '/path/to/directory2' \
;do
    chmod 775 "$i"
    chown -R http:http "$i"
    cd "$i" && \
    find . \
       -type d -exec chmod 775 {} \; \
                  -o \
       -type f -exec chmod 664 {} \;
    done

Объяснение

Поскольку вы выполняете тот же набор операций с dir1 / 2/3, имеет смысл переместить их в цикл.

Две команды поиска также можно переместить внутрь одной с помощью правил логической логики.

1
28.01.2020, 02:46

Теги

Похожие вопросы