shell脚本错误 - 'expecting do'错误

时间:2016-09-13 16:21:38

标签: shell

Screenshot of the workspace 我使用shell脚本直接从PDB服务器下载多个PDB文件。我尝试运行脚本时收到此错误。 在终端中,我键入了以下内容。

  

sh a.sh

a.sh:2:a.sh:语法错误:单词意外(期待“做”)

a.sh

for i in 'cat list'
do
wget http://www.rcsb.org/pdb/files/$i.pdb.gz
done

列表 1HLG 5EW4

1 个答案:

答案 0 :(得分:0)

这不符合人们的期望:

for i in 'cat list'

在上文中,'cat list'是固定字符串。 i上的循环将只运行一次,值为i='cat list'

如果要循环遍历文件列表的内容,有些人会运行:

for i in `cat list`

或者:

for i in $(cat list)

然而,上述内容使list的内容受到分词路径名扩展的影响,这可能不是您想要的。为避免这种情况,请运行:

while IFS= read -r i
do
   wget "http://www.rcsb.org/pdb/files/$i.pdb.gz"
done <list

以上wget的每一行list运行一次listlist行不变。 (如果IFS=的行包含您要忽略的前导或尾随空格,请从代码中删除$i。)

请注意,在上面的代码中,shell变量 selectedImage = null; orientation = -1; selectedImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; // Get the cursor Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); Cursor cursorF = getContentResolver().query(selectedImage, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null); // Move to first row cursor.moveToFirst(); if (cursorF == null || cursorF.getCount() != 1) { orientation = 90; //Assuming it was taken portrait } else { cursorF.moveToFirst(); orientation = cursorF.getInt(0); } //Toast.makeText(this, "orientation: " + orientation, Toast.LENGTH_LONG).show(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); imgDecodableString = cursor.getString(columnIndex);//imgDecodableString = percorso completo immagine cursor.close(); bmpImage = BitmapFactory.decodeFile(imgDecodableString); bmpImage = RotateBitmap.rotateImageIfRequiredFile(bmpImage, orientation); ImageView imgView = (ImageView) findViewById(R.id.imgView); // Set the Image in ImageView after decoding the String imgView.setImageBitmap(bmpImage); //name of image String sFilePath = getRealPathFromURI(selectedImage); String saPathParts[] = sFilePath.split("/"); String sFileName = saPathParts[saPathParts.length - 1]; filename = sFileName; Toast.makeText(this, "filename:" + filename, Toast.LENGTH_LONG).show(); if (bmpImage == null) { Toast.makeText(getBaseContext(), "Image invalid", Toast.LENGTH_SHORT).show(); } } 在双引号内使用。这可以防止对URL执行分词路径名扩展