2

I'm writing a script that allows a user to enter in a folder of there choice. Upon completion, the script will then search starting from the root for the folder and display all the files within that only have Write permission for the Other category. Here's what I've got so far, and I know my problem lies within a minor find option, hopefully someone can help.

echo -e "Enter a Folder Name Below\n"
read foldername
answer=$(find -prm -o+w / -name $foldername 2>/dev/null)
if [ "$answer" = "" ]
then
    clear
    echo -e "\n\n That Was Bad Input" 
else
    clear
    ls -l $answer
fi
read pause
3
  • What is the error you are seeing or what does not work?
    – rahul
    May 6 '15 at 20:19
  • It defaults to my statement of "This Was Bad Input" every time I enter a folder name when prompted. I'm not sure if order matters when using multiple options with the find command, or if I am leaving an option or two out. I'm using a bash shell with just a terminal window. May 6 '15 at 20:25
  • Run your find command from a terminal to make sure it's giving you the output you expect it to before trying to wrap it in a script.
    – cohensh
    May 6 '15 at 21:05
0

There are a couple of improvements needed for your script. It's good practice to quote your variables "$folder" , "$answer". You need to use -z and -n to test for null/not null strings in your script. It's better to use read -r especially when reading input with slashes. You also need to change the order of the arguments in your find command. Depending on your shell , you may want to use wholename instead of name. Here is a working version you can consider.

#!/bin/bash
echo -e "Enter a Folder Name Below\n"
read -r foldername
answer=$(find / -type d -perm /o+w -wholename "$foldername" 2>/dev/null)
if [ -z "$answer" ]
then
    clear
    echo -e "\n\n That Was Bad Input" 
else
    clear
    ls -l "$answer"
fi
read pause
-1

You have a syntax error in your find options. It's -perm, for example:

$ find $foldername -type f -perm -o+w

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.