LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   create script that finds files- directory and something else (https://www.linuxquestions.org/questions/linux-newbie-8/create-script-that-finds-files-directory-and-something-else-4175581964/)

hexle 06-10-2016 02:33 PM

create script that finds files- directory and something else
 
Create a script named dirstat.What i should do is to find if is a file,directory or something else.For example to appear this messages : file1 is file .Desktop is directory. Public is something else.dirstat is file.
Hint :This exercise i was tryed alone to do it . If your answers is go there to study this ok ,better it would be not to come here for help ,isnt the right place.This is what i tryed i have study a lot i didnt find another exercise similar to it for that i came to this placeso if you would like to help me with the exercise.

Code:

$vi dirstat
#!/bin/sh
for i in *; do
if [ -f file1]
echo -n "file1 is file"
elif [ -d desktop)
echo -n "desktop is directory"
elif [ -p public ] // I am not sure for -p
echo -n "Public is something else"
fi
done


dab1414 06-10-2016 03:44 PM

Look at this for file test operators
http://tldp.org/LDP/abs/html/fto.html

Habitual 06-10-2016 03:46 PM

Code:

man test
for -p switch/option

keefaz 06-10-2016 04:50 PM

why no test on $i?

ondoho 06-11-2016 03:18 AM

really?
after this?
the answers are in that thread.
let me recap:
Quote:

instead of desperately trying to understand something that is way above your head, start with something smaller that you can grasp.
learn bash from the ground up!
maybe this can help you:
https://www.howtoforge.com/tutorial/...pting-lessons/
Quote:

And if you did put effort into this, you would have, at the VERY LEAST seen that bash scripts don't use // for comments....but you didn't. If you want to learn, then as you've been told SEVERAL TIMES in this thread, look at EACH LINE...and figure out what that line does.

grail 06-11-2016 04:32 AM

You have explained you are doing a Java course and you clearly are not wanting to try and learn bash scripting, so I am wondering why you are bothering with these questions?


All times are GMT -5. The time now is 06:03 PM.