019 Bash

26 Oct 2012

[Bash](http://en.wikipedia.org/wiki/Bash_(Unix_shell) is a Unix shell and it is available by default in Linux and MAC. It is very useful as a developer to know shell scripting and we will explore how to automate tasks (shell scripting), set profile configurations (bash profile) and schedule tasks (cron job) - all in the name of efficiency!

Download video: mp4

Similar episodes: 002 Terminal

##Background on Bash:

  1. Why I should learn Shell Scripting?
  2. What is a Unix Shell and types of Unix shell such as [bash](http://en.wikipedia.org/wiki/Bash_(Unix_shell) and zsh?
  3. Bash programming
  4. Bash guide for beginners
  5. Advanced bash scripting guide
  6. What is a Cron job

##Things to learn with Bash

####1. basic logic

Open up the [Terminal App] and type in the followng to play around with basic shell logic:

#!/bin/bash
STR="Hello World!"
echo $STR

####2. shell scripting

#!/bin/bash
STR1="foo"
STR2="bar"
if [ "$STR1" = "$STR2" ]; then
    echo String 1 is the same as String 2
else
    echo String1 is not the same as String 2
fi
#!/bin/bash
for i in `seq 1 10`; do
  echo $i
done
#!/bin/bash
function hello {
   echo Hello from the function!
}
hello
#!/bin/bash
function e {
    echo $1
}
e Hello
e World
#!/bin/bash
echo Which unix shell do you use?
read FIRST SECOND
echo "Awesome! You use $FIRST, $SECOND !
#!/bin/bash
echo What is your project name?

read PROJECT
mkdir $PROJECT
cd $PROJECT
touch index.html
mkdir js css img
touch js/script.js style.css

####3. bash profile

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/on \1/'
}
export PS1="\e[0;35m\u\e[m in \e[0;34m\w\e[m \e[0;32m\$(parse_git_branch)\e[m\no  "

####4. cron jobs

Use the command line:

##More Resources on Bash

  1. Shell scripting for mac
  2. sample bash profile
  3. customise bash prompt
  4. best practices for maintaining cron jobs and shell scripts

##Build Link of this Episode

Coursera offers courses online by partnering leading universities in the world.