In Shell Script Does Second Command Wait For First Command To Complete

Hi All,

I have a question related to Shell scripting. In my shell script, I have following two commands in sequence:

sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE

mv $TEMPFILE $ORIGFILE

The first command is operating on large number of data like 20k. Will it be possible that the second command is executed and rename the temporary file to original file name before the first operation is completed.

Thanks
Angshuman

until a process is complete the following process does not start, unless you run the process in the background, regardless of the running time.

Hi,

Thank you for your reply. This was also my understanding. I am not running the first process in background. However, I get the error intermittently that file does not exist. Hence, I wanted to confirm.

Thanks once again for your confirmation.

Angshuman

The error will occur when your command to create that file wont find any patterns which you are searching in the file thus no tempfile gets generated.

add below block to avoid it

 
if [ -f $TEMPFILE ] ; then
mv $TEMPFILE $ORIGFILE
fi