#!/bin/sh
init=step5_input
rest_prefix=step5_input
mini_prefix=step6.0_minimization
equi_prefix=step6.%d_equilibration
prod_prefix=step7_production
prod_step=step7
# Minimization
gmx grompp -f ${mini_prefix}.mdp -o ${mini_prefix}.tpr -c ${init}.gro -r ${rest_prefix}.gro -p topol.top -n index.ndx
gmx mdrun -v -deffnm ${mini_prefix}
# Equilibration
cnt=1
cntmax=6
while [ ${cnt} <= ${cntmax} ]
@ pcnt = ${cnt} - 1
istep=`printf ${equi_prefix} ${cnt}`
pstep= `printf ${equi_prefix} ${pcnt}`
if [ ${cnt} == 1 ] then pstep=${mini_prefix}
gmx grompp -f ${istep}.mdp -o ${istep}.tpr -c ${pstep}.gro -r ${rest_prefix}.gro -p topol.top -n index.ndx
gmx mdrun -v -deffnm ${istep}
@ cnt += 1
end
# Production
cnt=1
cntmax=10
while [ ${cnt} <= ${cntmax} ]
@ pcnt = ${cnt} - 1
istep=${prod_step}_${cnt}
pstep=${prod_step}_${pcnt}
if [ ${cnt} == 1 ] then
pstep=`printf ${equi_prefix} 6`
gmx grompp -f ${prod_prefix}.mdp -o ${istep}.tpr -c ${pstep}.gro -p topol.top -n index.ndx
else
gmx grompp -f ${prod_prefix}.mdp -o ${istep}.tpr -c ${pstep}.gro -t ${pstep}.cpt -p topol.top -n index.ndx
endif
gmx mdrun -v -deffnm ${istep}
@ cnt += 1
end发布于 2022-11-05 03:13:15
您的代码包含几个错误。我不知道@在csh中意味着什么,也不知道这个是否有效。不同的shell在语法上有一些不同,因此您应该看看sh、bash、zsh、dash等中使用的语法。
这是sh脚本的有效语法:
#!/bin/sh
init=step5_input
rest_prefix=step5_input
mini_prefix=step6.0_minimization
equi_prefix=step6.%d_equilibration
prod_prefix=step7_production
prod_step=step7
# Minimization
gmx grompp -f ${mini_prefix}.mdp -o ${mini_prefix}.tpr -c ${init}.gro -r ${rest_prefix}.gro -p topol.top -n index.ndx
gmx mdrun -v -deffnm ${mini_prefix}
# Equilibration
cnt=1
cntmax=6
while [ ${cnt} -le ${cntmax} ]; do
pcnt=$[ cnt - 1 ]
istep=$(printf ${equi_prefix} ${cnt})
pstep=$(printf ${equi_prefix} ${pcnt})
#One liner if statement:
if [ ${cnt} == 1 ]; then pstep=${mini_prefix}; fi
gmx grompp -f ${istep}.mdp -o ${istep}.tpr -c ${pstep}.gro -r ${rest_prefix}.gro -p topol.top -n index.ndx
gmx mdrun -v -deffnm ${istep}
((cnt += 1))
done
# Production
cnt=1
cntmax=10
while [ ${cnt} -le ${cntmax} ]; do
pcnt=$(( cnt - 1))
istep=${prod_step}_${cnt}
pstep=${prod_step}_${pcnt}
if [ ${cnt} -eq 1 ]; then
pstep=$(printf ${equi_prefix} 6)
gmx grompp -f ${prod_prefix}.mdp -o ${istep}.tpr -c ${pstep}.gro -p topol.top -n index.ndx
else
gmx grompp -f ${prod_prefix}.mdp -o ${istep}.tpr -c ${pstep}.gro -t ${pstep}.cpt -p topol.top -n index.ndx
fi
gmx mdrun -v -deffnm ${istep}
cnt=$[ cnt += 1 ]
done而 while语句的有效语法应该是:
while [ expr ]; do
code
done
#Or
while [ expr ]
do
code
done因此,如果您想要比较数字,您应该使用:
-le的意思是很少或等于-eq的意思是等于-lt意味着比-ge的意思是伟大或等于-gt的意思比如果 if语句的有效语法应为:
if [ expr ]; then
code
fi
#or
if [ expr ]
then
code
fi比较数字的expr与while费用相同。
Math操作在代码中有几种使用数学操作的方法,在这个脚本中,我使用了两种方法:
sum=$[ expr ]
#E.g.
pcnt=$[ cnt - 1 ]和
sum=$(( expr ))
#E.g.
pcnt=$(( cnt - 1))
#or if you are not assign a value:
((expr))
#E.g.
((cnt += 1))Setting变量当您设置某个变量时,如果您运行的话,您必须小心使用空格:
val = 10这将导致一个错误:命令找不到。因此,有效的语法是:
val=10
val='something'
val="something"
val=$(command)
val="$(command)"
val=`command`
val="`command`"关于将它们的输出分配给一个变量的run命令,我看到您有:
istep=`printf ${equi_prefix} ${cnt}`与其使用val=**`command`**,不如使用val=$(command),这更值得推荐:
istep=$(printf ${equi_prefix} ${cnt})https://unix.stackexchange.com/questions/723724
复制相似问题