# Lab 2
## Part 1
Instructions:
* Make a directory to work in :smile:
* Copy this into a file:
```
#!/bin/bash
echo "\$# $#"
echo "\$@ $@"
echo "\$0 $0"
echo "\$1 $1"
hello="suh dude"
echo "${hello}there"
if [ $# -ge 4 ] ; then
echo "SO MANY ARGUMENTS"
else
echo "few arguments"
fi
```
* https://stackoverflow.com/questions/2359270/using-if-elif-fi-in-shell-scripts#2359293
* https://www.linux.com/tutorials/using-spell-checking-vim/
* For loops: https://www.cyberciti.biz/faq/bash-for-loop/
* While loops: https://www.cyberciti.biz/faq/bash-while-loop/
* Commands to look up:
* echo: print to stdout
* cat: print file contents to stdout
* head: first ten lines
* tail: last ten lines
* wc: "word count," can be used for characters, words, or lines
* awk: Entire language. Great for more complicated file content manipulation. `cat text.tsv | awk '{print $2 $1'}`
* sed: Complicated regex stuff (on a per line basis).
* grep: Regex finder :smile:
* tr: Character replacer
* rev: Reverses input on a per line basis.
* cut: Cuts up the input string and gives back one field.
* curl: Grabs content from the internet
* find: Like grep, but on filenames
* which: What a command is, where it can be found
* cp: Copy a file
* mv: Move a file
* ssh: Ssh into another computer
* ln: Link files. Can be hard or soft links. Know the difference.
* mkdir: Make an empty directory.
* touch: Make an empty file.
* chmod: Change permissions
* chgrp: Change group.
* chown: Change owner.
* man: Read manual for a command
* id: List information about current user
* whoami: Print my username
* finger: look up other users.
## Part 2: GIfs!
Silo wants to put together some gifs from still images to entertain Tango; however, he doesn't want to [pay](https://www.movavi.com/support/how-to/how-to-make-time-lapse-video.html) for such a simple task or upload personal photos to an online service. With the power of tools like `bash` and `ffmpeg`, this should be a piece of cake! Help Silo create a gif using using your own pictures.
To create the gif, you will be using [`ffmpeg`](https://ffmpeg.org/) to create the gif from a set of images of your choice (it must be original!).
CS department machines should already have `ffmpeg` installed. If you are working locally, you can install it yourself on your machine (their website is linked above).
Using the images in [`gif_frames`](https://drive.google.com/drive/folders/1N7mD9aIz_YoYTyHYaWLebdx_za2LFeJA?usp=sharing)(or your own images if you're feeling creative), create your own gif or video from original images using `ffmpeg`. You should look at the `ffmpeg` documentation to see what this handy tool can do! If you want ideas for gifs/videos to make, this [blog post](https://miasnikovas.lt/2013/01/quick-tip-easy-time-lapse-videos-with-ffmpeg/) can be a useful reference!
Once you've determined the proper `ffmpeg` command with the appropriate options and arguments to create your gif/video, use it to create a bash script called `im2mv` which takes in a directory of images as input and generates a movie from it, saving it into a user-specified file path. Be sure to print a success message so users know if it worked!
In your script, you'll want to use `#!/bin/bash` as your shebang.
Example of usage (`>` represents the prompt):
```
> im2mv ./gif_frames my_gif.gif
GIF saved to transparront.gif
```
Here's the source code for the script!
```
#!/bin/bash
img_dir=$1
dest=$2
ffmpeg -i "$img_dir/image%03d.png" "$dest"
echo "Movie saved to $dest"
```
Now let's install your script so that it can be called anywhere!
1. Create a folder called `.local` under your home directory (`$HOME`) and then create another folder called `bin` in `.local`. If these directories already exist, move on to the next step.
2. Copy `im2mv` into `~/.local/bin`.
3. In `~/.bash_profile`, add the line `PATH=$HOME/.local/bin:${PATH}` so that bash knows that it contains your downloaded executable. Alternatively, you could directly run `echo 'PATH=$HOME/.local/bin:${PATH}' >> ~/.bash_profile` to do this.
4. Run `source ~/.bash_profile` or open a new terminal instance to see your edits to `.bash_profile` take effect. Try running `im2mv` from any directory!
When you're done with everything, show off to your neighbors or TAs!
Image credit for `gif_frames`: [source](https://cultofthepartyparrot.com)