Bakunin, I had tried using absolute paths, as my statement has multiple steps in between, the value of 'file' is lost in each step.
I do not think that the value "file" is "lost", i just think that "file" at each step doesn't contain what you think it does. This is your code:
The first thing is: do NOT write one-liners. It is hard to understand what is going on when. So first, let us reformat:
Next thing: make sure that each step really does what you think it does. Notice that i took the final manipulation out of the cp command for clarity:
Now run that and observe: does "$file" in every step really contain what you expect it to contain? I suppose it doesn't. It is not "lost" IMHO. To quote from your post #1:
Quote:
Originally Posted by HikingLife
Basically check for all files with name like CAT_TURNAROUND_201811120_075221_3.done in the folder ABC/DEF/*.done, then get all the files starting with just this part CAT_TURNAROUND_201811120_075221 from this directory /ABC/DEF/ copied to /ABC/EDG/
So let us assume the content of "$file" is "CAT_TURNAROUND_201811120_075221_3.done" or "/ABC/DEF/CAT_TURNAROUND_201811120_075221_3.done", depending on you using absolute pathes or not. Running the manipulations above would give:
As you can see the one manipulation in the middle does absolute nothing. It can't do anything, because you cut off any "." that is in a files name with your first manipulation! And the last manipulation depends entirely on the exact length of the filename. What would it do with, say, "HORSE_TURNAROUND_201811120_075221_3.done"?
Let us try again: you want to cut off the extension (".done") from the filename. Fine! Then just do so! You know from the for-loop that all the values of "$file" will have exactly ".done" as extension, so there is no need for ${file%.*}. Do it explicitly: ${file%.done}. The net manipulation doesn't do anything (and will never do anything, see above), so get rid of it. Now for the last one: it produces the correct result in your example but as i have shown you it might break with other values. Taking a step back: we want to cut off everything up to the last underscore ("_") from the filename. So let us do that: ${file%_*}.
Notice that we could have done so immediately without all the intermediary steps! This of course is only the case as long as the extension contains no underscore. So until you change your for-loop to something like for file in *.do_ne you can just skip all the steps and use just the last one i suggested.
Would the result be any different if we use absolute pathes? No, because we only cut off from the end where the filename is.
:confused:
Hi All,
This script is not working. I want to change the directory as per users selection in current shell. Looks like it is spawning sub-shell internally.
I have used
. changedir.sh
source changedir.sh
./changedire.sh
But did not work. Currently shell directory remain the... (4 Replies)
Hi men,
I think this must be a very common job. "How could to Automatically change to Bash shell after login and then jail user can only using this shell".
I want monitor user works.However it just only effect on Bash shell. Consequently if the user change the shell it will be worthless.
... (4 Replies)
System: Ubuntu Intrepid Ibex
I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files.
So, take the following file:
/home/slag/www/webcam.jpg
Rename it--preferably with a time stamp.
Place it in say:
/home/slag/www/history/
... (4 Replies)
Hi,
I am trying to change the directory in my script, & want to check if the directory is present or not .
Ex:
cd /home/xyz/temp/logs
if the logs directory is not present i want to show the error in script instead of shell script error.
Can anybody please help me on the same
Thx in... (2 Replies)
HI,
I need to change the working directory by using the shell script
/Export/home/user_name
I have to go one step back like
/Export/home
Please help on this.:confused: (3 Replies)