OK ... not to be too harsh, but we need to go step by step (not sure if you are doing this, if you are I apologise)
Firstly i wanted to mention something about post #17 where you wrote:
When any command is executed, along with the output you may require it also has an exit code/status represented by $?, ie
clfs grail -- this is my output
0 -- zero equals success, other possibilities are between 1 and 255
$>ls /homes -- this directory does not exist on my machine
ls: cannot access /homes: No such file or directory
As you can see from the above you can test if the mount is successful by testing if $? = 0 (actually -eq in bash for = number)
then place rest of tests inside the if to continue on success
3b. Now there are many tools but the simplest is probably to grep the above "line" from the file with the previous data and do an "if" on the
result. true ignore, false put it in ... or something like that
grep is a command that allows you to look into a text file and find matches to particular text and/or patterns:
grep loop2.avi test2.txt
grep "*.avi" test2.txt
The first will return any lines it finds in test2.txt that contain "loop2.avi" ( I would add that it also matches "thisloop2.avi", but we will get to that)
The second looks for all lines containing zero or more of any character followed by ".avi" and returns them.
So the "if" I was referring to was to test that the grep was successful or not, ie the exit code I mentioned above for mount.
Now back to recent posts of errors, as you have a few errors this would be why I suggest the step by step approach above.
Any error after the first cannot really be looked at until the prior ones are solved (I know this may be obvious, but i just thought I would put it out there)
So things to look at:
tv2="$(find $tv -type f -name "*.avi")"
This does not return an array but rather a string of all your avi files.
the issue with this from the testing point of view is it is one long string and so your "test2.txt" file would need to be in the same format
for the testing to work, which I am guessing it is not, but rather that you have one line per file name (please correct me if i am wrong here?)
This being said, the following line works as you expect due to it being a successfully printed string:
echo ****the contents of old***
Now this is one of those try it on the command line first and then stick it in the script type of things.
There a couple of problems here:
a. old=sed - from bashes point of view, this is where the first command ends as it is an assignment of the string sed to the variable old
b. /home/mrgreaper2004/test2.txt - execute this string of text as a command, which of course will not work
c. as a. & b. demonstrate the echo here is incorrect
To add to this point, this is where you would need to use either the grep or loop idea to check your file. sed is the wrong tool and will not work the way you have it even if you had placed it in command substitution characters like so:
This will generate an error.
new="$(echo -e "$tv2$old"|sort -d|uniq -u)"
echo ****the contents of new****
As stated above, we cannot continue to this code with the prior errors in place as the next line then references "$old" which is not what we expect it to be.
However, I would again suggest writing the "echo" part piece by piece until you get to the "uniq" command to actually see what sort of output you will get.
For this test you will need to manually enter the values for "$tv" and "$old". I think you may be surprised at what it returns.
#next to copy the filed
cp $new /home/mrgreaper2004/testfold/
#for testing purposes saves the current list
echo "$tv2" > /home/mrgreaper2004/test.txt
#now to create the list of old episodes for use with the next time the script is run
echo "$tv2" > /home/mrgreaper2004/test2.txt
Assuming all the previous corrections were made, these line will more than likely work.
Again I would urge you to test how the last two "echo"s would behave on the command line and i would stress not to use a file where you wish to keep the contents (hint)