Fair enough, no problem. You are welcome.
So, that is a start. Let us go over it. Notice that i will address some general points about script development which may not help you for this script but in the long run.
First, you should make it a habit to declare the variables you use. Not because this is always necessary (unlike in C or other languages you can "make variables up" on the fly simply by using it) but because this is a good start to think over the algorithm you are going to employ, what information every part of it needs and so on. Furthermore you get some documentation for free.
So, let us start: you want a directory to put your results there and you want to create it. Question: what should happen if the directory already exists, i.e. from a former run of the script? Use it again? Create a new one? Overwrite the files there? Number the files so that results from diferent runs can exist alongside?
Second: this is a typo:
#!/bin/bash
# create a new directory motifs if it doesn't exist
mkdir -p motif
cd motifs
Don't worry - typos happen to all of us. But wouldn't it be nice to avoid such typos? Actually you can, by using a variable instead of a fixed name. And, by the way, is it really a good idea to put the directory in the current directory? Wouldn't it be better to create a directory in your HOME, regardless of where you currently are when you call the script? So, how about doing it like this:
#!/bin/bash
declare targetdir="/home/youruser/mywork/motifs" # directory for motifs
mkdir -p "$targetdir"
cd "$targetdir"
You see, now you can use "$targetdir" in your script and if you want to change the location you will have to do it only in one place - and it is easy to understand where that is because of the comment! Well written scripts are easy to read and easy to maintain.
Another point: don't use "cd" in a script! Use absolute pathes so that the script works regardless of where you stand. or from where you call it always in the same way.
touch motif_count.txt
> motif_count.txt
you actually do not need the first line because the redirection will create the (empty) file if it doesn't exist. Adding the path (instead of the "cd") we get:
#!/bin/bash
declare targetdir="/home/youruser/mywork/motifs" # directory for motifs
declare countfile="motif_count.txt" # count file
declare motif="" # buffer
declare allmotifs="ATG GGGGG ATTTT" # list of motifs to process
mkdir -p "$targetdir"
> "${targetdir}/${countfile}"
for motif in $allmotifs ; do
....
done
Let us pause here, it is getting quite late for me. More on the script tomorrow, but you might want to go over the question above and us what you wnat the script to do. Further, you may want to explain what your script does not do or does wrongly. Finally, a bit more information about your environment: OS, version, .... - might also help because some systems have special provisios others do lack.
I hope this helps.
bakunin