Bash scripting is like writing a recipe for your computer - it's a series of commands that:
Shebang Line (#!): First line starting with #!
- Tells the computer this is a Bash script
- Always use: #!/bin/bash
Comments: Lines starting with #
- Ignored by the computer
- Help explain your code
Commands: Instructions to execute
- Same commands you'd type in terminal
- Example: echo, grep, wc
Creating FASTA File:
- echo writes lines to sequences.fasta
- > indicates sequence names
Counting Sequences:
- grep -c '^>' counts lines starting with >
Calculating Length:
1. grep -v '^>': Exclude header lines
2. tr -d '\n': Remove line breaks
3. wc -c: Count characters
GC% Calculation:
1. tr -cd 'GC': Keep only G/C
2. bc: Calculator for percentage
dna_analysis.sh| Concept | Example | Purpose |
|---|---|---|
| Variables | total_length=... | Store values |
| Command Substitution | $(...) | Capture command output |
| Pipes (|) | cmd1 | cmd2 | Pass output between commands |
| Redirection (> ) | echo ... > file | Write to file |