I have several input files for a program installed in my ubuntu, I can do it manually and put

keyword teste.in

But since I have a really large number of files all with different names I would like to make this automatic. Is it possible to create a queue here the script submits the first job and when this is finished it submits the following one and then all the others one at a time?


  • Can you describe in more detail what it is you want to do, with a more complete example? – Elias Apr 5 at 16:24
  • 1
    I'm using a program called QE that is a modelling code that reads a quite complex input file name.in So, I've several ZZYX.in XXY2.in YZX3.in .... and I need to run all of them after each other. Usual to run I need to write in the command line ~qe name.in but now I would like to make a queue like a script that submits one after each other with qe inputname.in – user9251343 Apr 5 at 17:10

You can do something like the following. Suppose I have several files in a directory, in my little test case I have three files called a.txt b.txt c.txt. Then in bash I can use a for loop like this:

for name in `ls` ; do echo now name is $name ; cat $name ; done

The variable $name will contain the current filename, and it will loop through all the filenames listed by the ls command. Of course, instead of the "cat $name" that I used for my test, you would use your own command, like "qe $name" or whatever.

If you don't like separating things with semicolons as above, you can instead write it on separate lines in a script file, like this:

for name in `ls` ; do
  echo now name is $name
  cat $name

The "echo now name is $name" part is not necessary, it is just something I like to have to see what the script is doing.

  • 1
    This is great thanks – user9251343 Apr 5 at 18:50
  • @user9251343 Great, set it as "accepted" answer then :-) – Elias Apr 5 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.