我是bash脚本新手。我想逐行读取包含表格的文件。在每一行,我想将值分配给变量。这基本上是我的代码格式:
#!/bin/bash
experiment_database="/home/gperron/datasets/ENCODE_tables/final_tables/test_experiment_database.txt"
file_database="/home/gperron/datasets/ENCODE_tables/final_tables/test_file_database.txt"
EXPERIMENT=`cat $experiment_database | head -n $PBS_ARRAYID | tail -n 1 | cut -f1`
echo "EXPERIMENT #$PBS_ARRAYID: $EXPERIMENT"
while IFS= read -r line; do
echo $file_ID $experiment $target $biological_replicate $technical_replicate $read_number $url $fastq_file $genome
if [ "$experiment" == "$EXPERIMENT" ]; then
if [ $biological_replicate == 1 ]; then
if [ $technical_replicate == 1 ]; then
if [ $read_number == 1 ]; then
ID_111= $file_ID
fastq_111= $fastq_file
url_111= $url
echo "FASTQ file 111 ID: $ID_111"
echo "FASTQ file 111: $fastq_111"
echo "FASTQ file 111 url: $url_111"
elif [ $read_number == 2 ]; then
ID_112= $file_ID
fastq_112= $fastq_file
url_112= $url
echo "FASTQ file 112 ID: $ID_112"
echo "FASTQ file 112: $fastq_112"
echo "FASTQ file 112 url: $url_112"
fi
elif [ $technical_replicate == 2 ]; then
if [ $read_number == 1 ]; then
ID_121= $file_ID
fastq_121= $fastq_file
url_121= $url
echo "FASTQ file 121 ID: $ID_121"
echo "FASTQ file 121: $fastq_121"
echo "FASTQ file 121 url: $url_121"
elif [ $read_number == 2 ]; then
ID_122= $file_ID
fastq_122= $fastq_file
url_122= $url
echo "FASTQ file 122 ID: $ID_122"
echo "FASTQ file 122: $fastq_122"
echo "FASTQ file 122 url: $url_122"
fi
elif [ $biological_replicate == 2 ]; then
if [ $technical_replicate == 1 ]; then
if [ $read_number == 1 ]; then
ID_211= $file_ID
fastq_211= $fastq_file
url_211= $url
echo "FASTQ file 211 ID: $ID_211"
echo "FASTQ file 211: $fastq_211"
echo "FASTQ file 211 url: $url_211"
elif [ $read_number == 2 ]; then
ID_212= $file_ID
fastq_212= $fastq_file
url_212= $url
echo "FASTQ file 212 ID: $ID_212"
echo "FASTQ file 212: $fastq_212"
echo "FASTQ file 212 url: $url_212"
fi
elif [ $technical_replicate == 2 ]; then
if [ $read_number == 1 ]; then
ID_221= $file_ID
fastq_221= $fastq_file
url_221= $url
echo "FASTQ file 221 ID: $ID_221"
echo "FASTQ file 221: $fastq_221"
echo "FASTQ file 221 url: $url_221"
elif [ $read_number == 2 ]; then
ID_222= $file_ID
fastq_222= $fastq_file
url_222= $url
echo "FASTQ file 222 ID: $ID_222"
echo "FASTQ file 222: $fastq_222"
echo "FASTQ file 222 url: $url_222"
fi
fi
fi
fi
done < test_file_database.txt
我收到此错误:&#34; while循环错误:语法错误接近意外令牌`done&#39; &#34;
知道我的代码有什么问题吗?我曾尝试查看与同一错误相关的其他几个问题,但我无法修复我的代码。谢谢你的帮助!
编辑:这是整个代码。它可能有其他错误(我真的是初学者),但我希望它有所帮助。
<asp:GridView style="direction:rtl; " ShowHeader="False" BorderColor="White" BorderWidth="2px" HeaderStyle-BackColor="#926c3f" HeaderStyle-Font-Bold="false" RowStyle-BorderColor="White" ID="GridView1" runat="server" DataSourceID="XmlDataSource1" AutoGenerateColumns="False" CssClass="auto-style100" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="GridView1_SelectedIndexChanged" OnRowCancelingEdit="GridView1_SelectedIndexChanged" OnRowEditing="GridView1_SelectedIndexChanged" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText=" שם משחק" ItemStyle-Width="200px" >
<ItemTemplate >
<asp:Label ID="NameLabel" runat="server" Text='<%#Server.UrlDecode(XPathBinder.Eval(Container.DataItem, "gameName").ToString())%>'> </asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="nameTB" runat="server" Text='<%#Server.UrlDecode(XPathBinder.Eval(Container.DataItem, "gameName").ToString())%>'> </asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="קוד משחק" ItemStyle-Width="85px">
<ItemTemplate>
<asp:Label ID="codeLabel" runat="server" Text='<%#Server.UrlDecode(XPathBinder.Eval(Container.DataItem, "gameCode").ToString())%>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="הגדרות" ItemStyle-Width="70px">
<EditItemTemplate>
<asp:ImageButton ID="cancelImageButton" runat="server" ImageUrl="~/images/cancel.png" CommandName="cancel" OnClientClick="showWhoIsPublish" />
<asp:ImageButton ID="approveImageButton" theItemId='<%#XPathBinder.Eval(Container.DataItem, "@id")%>' runat="server" ImageUrl="~/images/approve.png" CommandName="approve" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="settingsImageButton" runat="server" CssClass="buttons" ImageUrl="~/images/אייקון הגדרות.png" theItemId='<%#XPathBinder.Eval(Container.DataItem, "@id")%>' CommandName="edit" OnClientClick="showWhoIsPublish" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="עריכה" ItemStyle-Width="70px" >
<ItemTemplate>
<asp:ImageButton ID="editImageButton" runat="server" CssClass="buttons" ImageUrl="~/images/אייקון עריכה.png" theItemId='<%#XPathBinder.Eval(Container.DataItem, "@id")%>' CommandName="editQ" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="מחיקה" ItemStyle-Width="70px">
<ItemTemplate>
<asp:ImageButton ID="deleteImageButton" CssClass="buttons" OnClick="doDelete_Click" theItemId='<%#XPathBinder.Eval(Container.DataItem, "@id")%>' runat="server" ImageUrl="~/images/אייקון מחיקה.png" CommandName="deleteRow" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" הגבלת זמן" ItemStyle-Width="90px" >
<EditItemTemplate>
<asp:DropDownList ID="DropDownListT" AppendDataBoundItems="True" runat="server" >
<asp:ListItem> 10 שניות</asp:ListItem>
<asp:ListItem> 20 שניות</asp:ListItem>
<asp:ListItem> 30 שניות</asp:ListItem>
<asp:ListItem> 40 שניות</asp:ListItem>
<asp:ListItem> 50 שניות</asp:ListItem>
<asp:ListItem> 60 שניות</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate >
<asp:Label ID="Time" runat="server" Text='<%#Server.UrlDecode(XPathBinder.Eval(Container.DataItem, "time").ToString())%>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="פרסום" ItemStyle-Width="60px">
<ItemTemplate>
<asp:CheckBox runat="server" ID="Checkbox1" CssClass="buttons1" theItemId='<%#XPathBinder.Eval(Container.DataItem, "@id")%>' AutoPostBack="True" OnCheckedChanged="PublishYesNo_CheckedChanged" ViewStateMode="Inherit" EnableViewState="True" Checked="False" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
如果我澄清了什么,请告诉我。
答案 0 :(得分:0)
在configureCell1
靠近顶部后,$biological_replicate == 1
在if [ $technical_replicate == 1 ]; then
之后没有fi
。见下文。
我想您可能对indirect expansion感兴趣,如下所示。 (可能很笨拙;我自己最近才发现间接扩张。)
elif
我认为这可能会对您的this_id="${biological_replicate}${technical_replicate}${read_number}" # e.g., 111, 112, ...
declare "ID_${this_id}"=$file_id # evaluates the left side into, e.g., ID_111, and sets $ID_111=$file_id
链条造成相当大的影响。
上面编辑的代码:
if