Shell – /bin/ls: Argument list too long

argumentscshfilesshell-scriptwildcards

I am a biology person and running a program named autodock. I have some files from ZINC library in .mol2 format. As per requirement I need to split this files with the csplit command and I received all the content in my directory. The parent file was split into very very many small files. Every file name is like this: ZINC14382748.mol2. Now I have to change all these files to pdbqt format and I have to use the following script:

#!/bin/csh # # $Id: ex02.csh,v 1.5 2007/07/19 21:52:59 rhuey Exp $ 
# 
# use the 'prepare_ligands.py' python script to create pdbq files 
cd $VSTROOT/VirtualScreening/Ligands 
foreach f (`ls *`) echo $f pythonsh ../../prepare_ligand4.py -l $f -d ../etc/ligand_dict.py end 

When I use it, it says

/bin/ls: Argument list too long

In short upon successful completion it will duplicate the above number of files into another format. So is there any reasonable solution to tackle this problem?

Best Answer

  1. Don’t parse the output of ls.  Just say foreach f (*).  Also,
  2. You should always quote your shell variable references (e.g., "$f") unless you have a good reason not to, and you’re sure you know what you’re doing.
Related Question