help explain my error in this array for BASH
Continuing from the work of yesterday, btw thanks again for all of the great help, I am onto the next step.
Here is what I attempted, but i ended with some odd results. Code:
[103236_rx30@rx30 ~]$ sh -xvv DEA-MOVE the first 3 results are as expected, but why did it continue to try to move everything.... I only want to move the files from the form inside of the deaopts.NY/OK/cnf on this computer. Code:
[103236_rx30@rx30 ~]$ cat DEA-MOVE |
You're not actually using any arrays (unless I'm missing something major)...
If you're referring to the 'find' functionality, you're not passing anything to 'deaclean' (is this your own code?) so ${1:3:3} expands to the empty string, and so find is matching '.*' - that is, anything which is hidden. |
deaopts.* is a list of files that contain data. when you set - `cat deaopts.foo` then you can echo out the string i am using and it will grab the first item in the file and print out the 3rd, - 5th char of that item.
|
So I seem to be a little lost with what this process is trying to do, so I figure I will just look at the errors and advise:
Code:
++ echo 'deaopts.*.orig' As solutions I would do the following 2 things: 1. Add shopt -s noglob to the start of the script and that way if the glob expands to nothing you will not enter the loop 2. Instead of wasting a call to tr, simply use parameter substitution: Code:
mv "$f" "${f^^}" Code:
deaopts.NY Code:
++ cat deaopts.NY As for the rest, apparently no other file is passed to set via cat and none of the other entries are in your output data??? Snark's explanation does hold some validity in explaining the last 4 entries which do match the glob of '.*', however I again do not follow why you would get to the last entry using the previous argument as it is not in the current directory. Maybe you should try to explain the purpose of the script before we try to assist in the errors? |
Quote:
Quote:
Code:
find: 123.*: No such file or directory What I have come up with is the following: Code:
#!/bin/bash Code:
[103236_rx30@rx30 ~]$ sh -xvv DEA-MOVE To answer question as to the goal of the script. I have a bunch of servers out there that are running some bad code (from long before i came to this company) that leaves the stores DEA reports in their $HOME directory. These clutter up the directory as well as make it a royal PITA for data transfer and backups. My goal is to clean up the $HOME directory of these stores and the file names used are as you see above. Yes i have obfuscated some of the above data, but the output you are seeing is from a test server without any real data from customers (they are all made up without real data) and the DEA#s are not real either. Thus semi safe to post :D> Each state has its own requirements for the file format, thus the deaopts.XX (NY, FL, etc... as you see above) ((side note, turns out the .fil is no longer used and should be removed thus my rm now at the top of the script)) the need for the 3rd - 5th chars of the first line in the deaopts.XX is the file format for that state. the first 2 chars are meaningless junk for my script and thus can be ignored. We do need to keep files that are younger then 15 days as several pharmacies will need to either reprint or retransmit that exact report. After 15days the reports are worthless to the store. Again thanks for all of the great help. |
i must of messed something up with the f^^
Code:
filemove () |
^^ was added in version 4 of bash, are you perhaps using an earlier version?
|
I see you've marked the thread as 'SOLVED' - well done for solving it, could you post something explaining to anyone who might have had a similar problem exactly what you did to solve it?
Thanks, |
the final working code:
Code:
[103236_rx30@rx30 ~]$ cat DEA-MOVE |
We could perhaps make it a little simpler:
Code:
#!/bin/bash |
very interesting ways you were able to tie stuff together. i did not know you could do that. very nice.
what is this bit of code: Code:
shopt -s nullglob |
nm, man shopt showed me what i needed to see on the nullglob. ty
i like that should help clean things up a bit. |
question and problem with the code...
Code:
[103236_rx30@rx30 ~]$ vi DEA2-MOVE |
Code:
in the script the array is not building properly would seem to be the logic you were following. If this is not the case or you are running from there and still getting errors, you will need to provide more detail on what error you are seeing / receiving? |
it is run from the same directory, but if you look at the full code i posted above i ran the script in sh -xvv so you could see the output, why is is looking to move all of the files in that directory?
Code:
find "${move_files[@]}" -mtime +15 -exec mv '{}' "$DIR" \; |
All times are GMT -5. The time now is 04:24 AM. |