Hi,
I am new in unix. I found one while command as while [ ! -z "$SRC_FILE" ].
It would be really help if you could let me know what is the use of "-z" and what is difference between "-n" and "-z". Thanks for your help!!
Last edited by Don Cragun; 02-12-2015 at 06:12 PM..
Reason: Add ICODE tags.
Thanks RudiC!!
in this case what will happen if there are five files with name 'xxx_yyy_*'?
will it rename all or only the first one?
I think in our case, only first file gets renamed and others are untouched.
thanks for help.
Moderator's Comments:
Please use CODE tags (not ICODE tags) for multi-line input, output, and code segment samples.
Last edited by Don Cragun; 02-12-2015 at 06:13 PM..
Reason: Change ICODE tags to CODE tags.
This is an overcomplicated approach to moving n files. You repeatedly list ALL files and then tail only the last - which is changing in every iteration as the former one has been moved. Some comments:
- no need to export - var is only used locally
- no need to use the -at options to ls
- the file_to_process.txt is not used anywhere
- the date stamp is evaluated in every iteration and will be changing between loops. Oh, I see, it's used to differentiate between files. Is that wise?
Anyhow, how about
Thanks RudiC!!
in this case what will happen if there are five files with name 'xxx_yyy_*'?
will it rename all or only the first one?
I think in our case, only first file gets renamed and others are untouched.
thanks for help.
Moderator's Comments:
Please use CODE tags (not ICODE tags) for multi-line input, output, and code segment samples.
Here is a slightly different take on what RudiC has already said about the above script...
There are several problems with this script (including, but not necessarily limited to):
The export command produces no output, so piping its output to tail doesn't do anything except make your script run slower.
There are no subshells or commands started by this script that will care whether or not a variable named SRC_FILE is present in their environment, so the export command is not needed.
There cannot be a space between a variable and the = or between the = and the value being assigned in a shell variable assignment statement (either on its own or in an export command).
Typing a command after an = in an assignment statement does not execute that command. You need to use command substitution to do that.
For filenames starting with "x", the ls -a option is a no-op.
Why re-evaluate the list of files to be processed every time you process a file? Why not just get a list of files and process them one by one?
Perhaps, something like this would better suite your needs:
The difference between this script and RudiC's suggestion is that the above script will run a little faster (since it doesn't execute the ls command) but it won't generate a diagnostic message if there are no files with names starting with xxx_yyy_ when you start the script (although one could be added as an else clause in the if statement. If there are files matching your pattern that are not regular files, this script will ignore them while RudiC's script will move them. And, since there is no delay between moves in RudiC's script, files could be overwritten if two or more files are moved within the same wall clock second. (The sleep 1 in the loop in my code avoids that problem. I don't see any need for the 10 second delay you had in your loop.)
And, finally to answer your question: "what will happen if there are five files with name 'xxx_yyy_*'?" I would expect a syntax error from the export command that will leave SRC_FILE undefined. So the expansion of $SRC_FILE in the while loop will be a zero length string and the commands in the while loop will never be executed unless your script inherits a value for that variable in its environment. If a value is inherited in the environment, zero or more files not matching your pattern could be moved or could cause a diagnostic message to be printed if mv can't move a file or several files (since you didn't quote the expansion in the mv command) named by that variable, and then the script would go on to do what you want because you reset that variable at the end of the loop each time you go through the loop.
Last edited by Don Cragun; 02-12-2015 at 08:20 PM..
Reason: Fix typo s/executed/moved/
Hi,
Can anyone please explain a little about df command. I have following question:
Following example is showing % used as 4 where as total free blocks are 15.46 out of 16.00 MB blocks.
df -m /test
Filesystem MBblocks Free %Used Iused %Iused ... (5 Replies)
Hey my friend was asking me if i knew a way to cout how many different words in a file. I told him no not off hand, but i was thinking about it, and i started to wonder also. I imagine this is probably pretty simple im just missing something, I keep confusing my self with how you would compair and... (16 Replies)
hallo, ik heb hier een vraagje. hoeveel gebruikers kunnen er op 1 unix systeem. hopelijk antwoorden golle nu want ik moet da vinde voor school en die leerkracht zaagt. :p
groetjes eu wacht wa was mijne nick ah ja vraagje
groetjes vraagje
ik kan geen engels dus antwoord liever in het... (1 Reply)
Hello
if I like to move file from defined directories system to new directory that not contained any directories system structure .
But I like to create the same file system structure as source directory for example :
I have 2 directories: foo1 and foo2
foo1 have directories and foo2 have... (2 Replies)
Now that I have getch() to work, I have yet another problem. BTW, thank you for answering these questions, I do ask a lot, only because I am eager to know, what is a board used for anyways :)
Ok, he's the problem...
#include iostream.h
#include conio.h
int main()
{
char movement;
... (2 Replies)