I'd like to advise that I am working on a homework project, thus I wouldn't exactly just like the answer, but instead to understand my commands and how to make this work.
Having said that I have this problem and a few potential solutions below:
1.a) Create a script which will read the names of the directories and links from the file etcdl3.txt and
- if the name is a valid directory name print the message
File “name” exist and is a directory
- if the name is a valid link print the message
File “name” exist and is a link
- Otherwise it should print the message
File “name” is neither a link nor a directory
Capture the output of this script in file etcdl4a.txt
Where the etcdl3.txt file looks something like this (But with more lines):
From the get-go I have a few questions that I can't seem to answer for myself. My teacher isn't the best at explaining things and I'm a little bit lost. In class, when we write our BASH scripts, he is able to do something similar to:
read X < etcdl3.txt
Which I guess runs through each line of text in the file. Correct? But how would I get a loop that will run through each line in the file until the end? "for X in..."? I'm familiar with the syntax in Java, but not so much in BASH.
Following that, for the if statements I would need to have (To determine if it's a link, directory, or neither) I would assume it would be akin to this:
if (something -eq "D")
echo "`cut -d'\t\t' -f2` is a directory"
elif (something -eq "L"
echo "`cut -d'\t\t' -f2` is a link"
echo "`cut -d\t\t' -f2` is neither a directory nor a link."
So I have two further questions:
1. Where I wrote "something", how would I isolate the first letter in each line? (as that's all I really need to determine what kind of file it is) Would a `grep '^d'` work in this situation?
2. In echo, I am allowed to back-tick in a cut command correct? Otherwise, how would I be able to get the name of the file? (I figured this would work as it's delimited by two tabs, and is the second field.
Thank you so much for your help.