我有一个脚本可以复制并粘贴其中包含一些文件的文件夹,并更改其中一个文件的某些值。事实是,导出的文件夹中的该文件随机显示为空白。因此,我想在脚本中添加一个检查点,以检查新文件大小是否大于0,如果不是,请再次重复该过程,直到文件大小大于0。 这是我到目前为止所得到的,但似乎无法正常工作:
path='/home/students/gbroilo/Desktop/Script'
file='prova.py'
step_x=1
while [ $step_x -lt 5 ]; do #maximum value of x
step_y=1
while [ $step_y -lt 5 ]; do #maximum value of y
cp -rf ${path}/Template ${path}/Template_${step_x}_${step_y} #copy folder and rename it with variable step x and y
cd ${path}/Template_${step_x}_${step_y} #change directory and open the Template folder
x=$( cat ${file} | sed -n '/x=[^0-9]*/p' | sed 's/[^0-9]*//g' ) #isolate the value of the x coordinate
x=$( expr ${x} + ${step_x} ) #define the increment of the x coordinate
y=$( cat ${file} | sed -n '/y=[^0-9]*/p' | sed 's/[^0-9]*//g' ) #isolate the value of the y coordinate
y=$( expr ${y} + ${step_y} ) #define the increment of the y coordinate
cat ${file} | sed "s/x=[0-9]*/x=${x}/g" | sed "s/y=[0-9]*/y=${y}/g" > prova.py #substitute the old value of x and y with their new incremented value
#command to export .med file to the right template directory
gawk -i inplace 'NR==455{print "try:\n Mesh_1.ExportMED( r\047/'${path}'/'Template_${step_x}_${step_y}'/Mesh_1.med\047,\
0,SMESH.MED_V2_2,1,None,1)\n pass\nexcept:\n print \047ExportToMEDX() failed. \
Invalid file name?\047"}1' ${file}
#check for size of the prova.py file
filesize=$(stat -c%s "prova.py")
echo "size of ${prova.py} = $filesize"
if (( filesize > 0 )); then
echo "file is correct"
else
cp -rf ${path}/Template ${path}/Template_${step_x}_${step_y} #copy folder and rename it with variable step x and y
cd ${path}/Template_${step_x}_${step_y} #change directory and open the Template folder
x=$( cat ${file} | sed -n '/x=[^0-9]*/p' | sed 's/[^0-9]*//g' ) #isolate the value of the x coordinate
x=$( expr ${x} + ${step_x} ) #define the increment of the x coordinate
y=$( cat ${file} | sed -n '/y=[^0-9]*/p' | sed 's/[^0-9]*//g' ) #isolate the value of the y coordinate
y=$( expr ${y} + ${step_y} ) #define the increment of the y coordinate
cat ${file} | sed "s/x=[0-9]*/x=${x}/g" | sed "s/y=[0-9]*/y=${y}/g" > prova.py #substitute the old value of x and y with their new incremented value
#command to export .med file to the right template directory
gawk -i inplace 'NR==455{print "try:\n Mesh_1.ExportMED( r\047/'${path}'/'Template_${step_x}_${step_y}'/Mesh_1.med\047,1)\n pass\nexcept:\n print \047ExportToMEDX() failed. \
Invalid file name?\047"}1' ${file}
fi
step_y=$(( ${step_y} + 1 )) #increment by one the current value of y
done
step_x=$(( ${step_x} + 1 )) #increment by one the current value of x
done