Я пытаюсь написать сценарий оболочки, который позволяет пользователю вводить разрешение, имя каталога и файл, чтобы исключить использование команды chmod. Кажется, я не могу заставить его работать правильно. Я очень новичок в сценариях оболочки, поэтому это может быть простая синтаксическая ошибка. Мой код показан ниже: ответПрисвоение разрешений chmod и исключение файла в скрипте оболочки Unix
#!/bin/bash
clear
echo " ====================================
We need our rights!
Set file permissions!
Only use numerical representation
of permissions listed below!
====================================
1) r. read access to a file
2) w. write access to a file
3) x. Execute access to a file "
echo "Please enter a permission:"
read permish
echo
echo "Please enter your directory name:"
read directory
echo
echo "Please enter a file to exclude:"
read exclFile
perm=""
if [ "$permish" -eq 1 ]; then
"$perm" = "u+r"
elif [ "$permish" -eq 2 ]; then
"$perm" = "u+w"
elif [ "$permish" -eq 3 ]; then
"$perm" = "u+x"
else
echo "invalid input"
fi
<chmod perm= "$perm" >
<fileset dir= "$directory" >
<exclude name= "**/$exclFile" />
</fileset>
</chmod>
echo "Done!"
Стефана Ферраро не было очень полезно для меня, но я решил мою проблему. Я просто пошла по-другому. Это был результат:
#!/bin/bash
clear
echo " ====================================
We need our rights!
Set file permissions!
Only use numerical representation
of permissions listed below!
====================================
1) r. read access to a file
2) w. write access to a file
3) x. Execute access to a file "
echo "Please enter a permission number
Exit with [x]:"
read permish
echo "Please enter a directory name:"
read dir
echo "Please enter a file to exclude:"
read xcldfile
case "$permish" in
1)
chmod -R u+r $dir
chmod u-r */$xcldfile
;;
2)
chmod -R u+w $dir
chmod u-w */$xcldfile
;;
3)
chmod -R u+x $dir
chmod u-x */$xcldfile
;;
x)
exit;;
*)
echo "invalid input. Try again"
sleep 2
bash HW2P1.sh
;;
esac
echo "Done!"
Ваше решение не является полным: Исключая средства, чтобы не выполнять «chmod» вообще для файла в $ xcldfile. –