Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page should serve as a reference for the many "things Linux" we use in this course. It is by no means complete – Linux is **huge** – but offers introductions to many important topics.

...

  • Macs and Linux have a Terminal program built-in
  • Windows options:

Use ssh (secure shell) to login to a remote computers.

Code Block
languagebash
titleSSH to a remote computer
# General form:
ssh <user_name>@<full_host_name>

# For example
ssh abattenh@ls6.tacc.utexas.edu

...

Code Block
languagebash
today=$( date );          echo $today  # environment variable "today" is assigned today's date
today="Today is: `date`"; echo $today  # "today" is assigned a string including today's date

Bash control flow

the bash for loop

As in many programming languages, a for loop performs a series of expressions on one or more item 's in the for's argument list.

The general structure of a for loop in bash are shown below. The <expression> <items> should be (or evaluate to) for's argument list: a space-separated list of items (e.g. 1 2 3 4 or `ls -1 *.gz` ).

Code Block
languagebash
for <variable name> in <expression><items>
do 
  <something>
  <something else>
done

Example, using the seq 4 command to generate a set of 4 numbers: 1 2 3 4.

Code Block
languagebash
for num in `seq 4`
do 
  echo $num
done

# or, since bash lets you put multiple commands on one line 
# if they are each separated by a semicolon ( ; ):
for num in `seq 4`; do echo $num; done

Here num is the name I gave the variable that is assigned a different number each time through the loop (called the loop's formal argument). The set of such numbers is generated by the seq 4 command. Each number is then referenced as$num inside the loop.

processing multiple files in a for loop

One common use of for loops is to process multiple files, where the set of files to process is obtained by pathname wildcarding. For example, the code below counts the number of reads in a set of compressed FASTQ files:

Code Block
languagebash
titleFor loop to count sequences in multiple FASTQs
for fname in *.gz; do
   echo "$fname has $((`zcat $fname | wc -l` / 4)) sequences"
done

...