...
The bash shell treats dollar sign ( $ ) as an evaluation operator, so will normally attempt to evaluate the environment variable name following the $ and substitute its value in the output (e.g. echo $SCRATCH). But we don't want that evaluation to be applied to the {print $1 / 4} script argument passed to awk; instead we want awk to see the literal string {print $1 / 4} as its script. To achieve this result we surround the script argument with single quotes ( ' ' ), which tells the shell to treat everything enclosed by the quotes as literal text, and not perform any metacharacter evaluation.
(Read more about Quoting in the shell)
Processing multiple compressed files
...
Code Block | ||||
---|---|---|---|---|
| ||||
cd $SCRATCH/core_ngs/fastq_prep
for fname in *.gz; do
echo "Processing $fname"
echo "..$fname has `zcat $fname | wc -l | awk '{print $1 / 4}'` sequences"
done |
...
Each time through the for loop, the next item in the evaluation expression argument list (here the files matching the wildcard glob *.gz) is assigned to the for loop's formal argument (here the variable fname). Note that items in the evaluation expression are separated by spaces – not Tabs.
...
The bash shell lets you put multiple commands on one line if they are each separated by a semicolon ( ; ). So in the above for loop, you can see that bash considers the do keyword to start a separate command. Two alternate ways of writing the loop are:
Code Block | ||
---|---|---|
| ||
# One line for each clause, no semicolons
for <variable name> in <expression>
do
<something>; <something else>
done |
...
language | bash |
---|
...
The actual filename is then referenced as$fname inside the loop. (Read more about Bash control flow)