ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I made a script that changes ownership and chmod of files and dirs in a folder from which I execute it. Here is the script:
Code:
#!/bin/bash
#
EXECMOD=700
FILEMOD=600
USER=root
GROUPE=root
for FILE in $( find . )
do
#Change ownerships
chown -v $USER:$GROUPE "$FILE"
#Give folders exec mod
if [ -d "$FILE" ]
then
chmod -v $EXECMOD "$FILE"
#If file is a bash script give it exec mod
elif head -n 1 "$FILE" | grep "#!/bin/bash" 1>/dev/null || head -n 1 "$FILE" | grep "#!/bin/sh" 1>/dev/null
then
chmod -v $EXECMOD "$FILE"
#If file ends with *.sh, *.csr, *.bin or starts with rc.*, give exec mod
elif [ -f "$FILE" ] && echo "$FILE" | grep *.sh 1>/dev/null || echo "$FILE" | grep *.csh 1>/dev/null || echo "$FILE" | grep *.bin 1>/dev/null || echo "$FILE" | grep rc.* 1>/dev/null
then
chmod -v $EXECMOD "$FILE"
#Else give plain (noexec) mod
else
chmod -v $FILEMOD "$FILE"
fi
done
My problem is that when "find" finds a file which has a space in its filename, var $FILE becomes part of the filename and not the whole name of a file, for example:
find found:
U2 - Bad.mp3
$FILE="U2", then $FILE="-" and $FILE=Bad.mp3 and it should be $FILE="U2 - Bad.mp3".
Is there a way this could be done? Or do you have a better idea for my script
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.