1
사용자가 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!"
Stephan Ferraro의 대답은별로 도움이되지 않았지만 문제는 해결되었습니다. 나는 다른 방식으로 그걸 보았습니다. 이 스크립트에 아무 상관이없는 것처럼 XML-태그 :
#!/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!"
해결책이 완료되지 않았습니다. 제외는 $ xcldfile에있는 파일에 대해 "chmod"를 전혀 실행하지 않는 것을 의미합니다. –