首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ubuntu shell脚本中,在while循环中使用EOM时出现语法错误

在ubuntu shell脚本中,在while循环中使用EOM时出现语法错误
EN

Ask Ubuntu用户
提问于 2021-11-09 15:16:46
回答 1查看 258关注 0票数 0

我有一个包含命令的代码,其中提示用户从菜单中显示的选项中选择一个选项。这需要重复执行几次,因此我使用了while循环。现在,我已经使用EOM (End of message)方法在提示时提供输入。在使用过程中,我注意到该方法在执行时会出现折叠错误。我已经将错误缩小到代码的这一部分(第80行到第83行),并且无法传递这个错误。

请帮我解决这个问题。

错误所在的行:

代码语言:javascript
复制
TEMP="q"
gmx_mpi make_ndx -f pull_sim.gro -o index.ndx <

错误:

代码语言:javascript
复制
./Run_Pull_Code.sh: 105: Syntax error: end of file unexpected (expecting "done")

请查找以下完整代码(请参阅此处第80至83行):

代码语言:javascript
复制
#!/bin/sh
# The above comment sets the sh file to execute as an interpreter (Line by line)

# Finding the current working directory
BASEDIR=$(pwd)
echo "I am currently in the following directory:"
echo "$BASEDIR"
echo " "


##########################################################################################
# Setting the pulling code positions and decrements (All in nm)
##########################################################################################
DECREMENT=0.5      #Steps in nm
RANGE=1            #From the highest to the lowest position
MID_POS=9.327      #Observing the highest water molecule (O atom) of the water surface
INIT_POS=$( echo "$MID_POS + $RANGE" | bc -l)  # Initial position
LAST_POS=$( echo "$MID_POS - $RANGE" | bc -l)  # Final position
CURR_POS=$INIT_POS # Assigning the Initial position as the current position


LOOP_CNT=0
while [ 1 -eq "$(echo "${LAST_POS} <= ${CURR_POS}" | bc)" ]
do 
    # increment the value
    LOOP_CNT=$( echo "$LOOP_CNT + 1" | bc -l)
    DISTANCE=$CURR_POS

    # Setting the loop number (X) as the pull code number for simulation (X)
    SIM_CNT=$LOOP_CNT

    # Making the directories (1) X_Pull (2) X_Pull/Making
    DIR_NAME_MAIN=$SIM_CNT"_Pull"
    mkdir $DIR_NAME_MAIN
    DIR_NAME_MAKING=$SIM_CNT"_Pull/Making"
    mkdir $DIR_NAME_MAKING
    
    echo " "
    echo "I have made the directories."
    echo " "

    # Copying the files from prerequisites folder to the newly created folder
    cp Prerequisites/Avo_decanol.pdb Prerequisites/water_box.pdb $DIR_NAME_MAKING
    cp Prerequisites/simulation_file.mdp Prerequisites/topol.top $DIR_NAME_MAIN
    
    ##########################################################################################
    # Making the simulation box "pull_sim.gro"
    ##########################################################################################
    cd $DIR_NAME_MAKING
    #(1) Fix the distance of the decanol from the water surface and make the only decanol box with the same dimension as that of the water box
    DISTANCE=9.5 
    gmx_mpi editconf -f Avo_decanol.pdb -o Dec_box.pdb -center 2.5 2.5 $DISTANCE -box 5 5 12
    #(2) CREATING CONSTANT HEADER AND ENDER cat files in PDB format
    #The first 4 lines of any PDB file contains the information of the box size and the name, etc.
    #Just copy the four lines into a separate HEADER PDB file by the following command.
    sed -n '1,4p' Dec_box.pdb > HEADER.pdb
    #The last 2 lines are also common to all PDB files, hence copy these to a ENDER PDB file by the following command.
    sed -n '38,39p' Dec_box.pdb > ENDER.pdb
    #(3) Separate the decanol atom properties from its PDB file (line 5 to 37) by the follwing command
    sed -n '5,37p' Dec_box.pdb > file_1.pdb
    #(4) Separate the water atom properties from its PDB file (line 5 to 15004) by the follwing command
    sed -n '5,15004p' water_box.pdb > file_2.pdb
    #(5) Now connect all the above files with the water surface PDB file in the following sequence:
    cat HEADER.pdb file_1.pdb file_2.pdb ENDER.pdb > pull_sim.pdb
    #(6) Rearrange all the number of atoms in the pull_sim.pdb and convert it into a GRO file, pull_sim.gro file.
    gmx_mpi editconf -f pull_sim.pdb -o pull_sim.gro -center 2.5 2.5 6.0 -box 5.0 5.0 12.0 -resnr 1

    # Copying the recently made pull_sim.gro file from making folder to the previous folder
    cd ../
    cp Making/pull_sim.gro ./
        
    echo " "
    echo "The pull box has been created."
    echo " "
    
    ##########################################################################################
    # Starting the simulation
    ##########################################################################################
    # (1) Making index file
    TEMP="q"
    gmx_mpi make_ndx -f pull_sim.gro -o index.ndx <
EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2021-11-09 15:51:11

Heredocs不能像脚本的其他部分那样缩进(除非您使用-EOM,但随后只能缩进选项卡)。毕竟,本文档的目的是允许您编写将以原样出现的东西。这意味着EOM不能这样:

代码语言:javascript
复制
while something; 
do
    command <

相反,EOM (或您使用的任何其他标记)需要是行中唯一的东西,因此在行之前或之后没有空白或其他任何内容。如下所示:

代码语言:javascript
复制
while something; 
do
    command <

另外,请注意,由于上述原因,还将包括前面的空格,以便:

代码语言:javascript
复制
c=0;
while [ $c -eq 0 ]; 
do
    cat <

将印刷:

代码语言:javascript
复制
$ foo.sh
    Hello!

而这一点:

代码语言:javascript
复制
c=0;
while [ $c -eq 0 ]; 
do
    cat <

将印刷:

代码语言:javascript
复制
$ foo.sh
Hello!

最后,在运行脚本时,我得到了一个不同的错误:

代码语言:javascript
复制
$ foo.sh
I am currently in the following directory:
/home/terdon/foo
 
/home/terdon/scripts/foo.sh: line 108: warning: here-document at line 84 delimited by end-of-file (wanted `EOM')
/home/terdon/scripts/foo.sh: line 109: syntax error: unexpected end of file

这将是因为我没有提供相同的输入数据,而且,由于您没有正确结束EOM,您的数据可能正在由脚本处理,这就是为什么您看到了不同的错误。我希望我的修复会摆脱它,因为它允许我在我的机器上运行您的脚本直到结束。

票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1374521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档