LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-10-2016, 02:33 PM   #1
hexle
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Rep: Reputation: Disabled
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
 
Old 06-10-2016, 03:44 PM   #2
dab1414
Member
 
Registered: May 2011
Location: OK, USA
Distribution: Slackware 14.1_64
Posts: 76

Rep: Reputation: 52
Look at this for file test operators
http://tldp.org/LDP/abs/html/fto.html
 
Old 06-10-2016, 03:46 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
man test
for -p switch/option
 
Old 06-10-2016, 04:50 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
why no test on $i?
 
Old 06-11-2016, 03:18 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
Old 06-11-2016, 04:32 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] move files or a directory to another directory using shell script user1111 Linux - Newbie 6 11-15-2013 08:13 AM
[SOLVED] Need help with script that finds the 10 largest files amber1 Linux - Newbie 12 03-28-2013 12:35 PM
[SOLVED] script to create same directory stucture kumarjohn Linux - Newbie 4 02-28-2013 01:45 AM
[SOLVED] Script Finds no Files dougp25 Programming 10 10-28-2010 09:54 AM
Need to create a script to move files from one directory to another mustang05 Solaris / OpenSolaris 4 06-16-2006 10:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration