Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
-
The problem statement, all variables and given/known data:
-
Recall that the env command provides a list of various environment variables available to you. Two of those variables are PWD, which is your current directory, and HOME, which is your home directory. Write a script named script7.sh to test to see if you are currently in your home directory. This will be true if $PWD is equal to $HOME. Output the result.
-
The following piece of code will loop through and print the files located in the current directory.
for file in $( ls )
do
echo $file
done
The condition [ -r $filename ] tests to see if $filename is readable. Write a script named script8.sh that uses a for loop to iterate through the current directory and test to see which files are readable. Output the names of all the readable files found in the directory. Include your script script8.sh as your answer to this problem.
- You can use the same logic that you used above by using the command cat $filename to output all of $filename.
for word in $( cat $filename )
do
echo $word
done
Write a script named script9.sh where, in place of $filename, you pass in a parameter of a text file�s name. This will be referenced as $1 in the script. Pass in a second parameter, a string, which will be referenced as $2. Using the for loop with cat, count the number of occurrences of the string ($2) in the file. Output the string ($2) and the number of times you found it in the file. Test this out on a few different text files to make sure it works. Include your script script9.sh as your answer to this problem.
- Relevant commands, code, scripts, algorithms:
- gives a hint as to what I need to be looking at with:
for file in $( ls )
do
echo $file
done
- gives a hint as to what I need to be looking at as well
cat $filename to output all of $filename.
for word in $( cat $filename )
do
echo $word
done
-
The attempts at a solution (include all code and scripts):
I'm having issues even attempting a solution. I would appreciate even advanced help on these, or give examples like what it should be showing. -
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Northern Kentucky University, KY, USA, Prof. Walker, CIT-130
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).