Thursday, August 11, 2011

Bash Basics

IO Redirection
  • 1>filename # Redirect stdout to file "filename."
  •  1>>filename # Redirect and append stdout to file "filename."
  •  2>filename # Redirect stderr to file "filename."
  • 2>>filename # Redirect and append stderr to file "filename."
  •  &>filename # Redirect both stdout and stderr to file "filename."
Bash basic arithmetic:

Surround your expression with double parenthesis .....
#!/bin/bash
x=5   # initialize x to 5
y=3   # initialize y to 3
add=$(($x + $y))   # add the values of x and y and assign it to variable add
sub=$(($x - $y))   # subtract the values of x and y and assign it to variable sub
mul=$(($x * $y))   # multiply the values of x and y and assign it to variable mul
div=$(($x / $y))   # divide the values of x and y and assign it to variable div
mod=$(($x % $y))   # get the remainder of x / y and assign it to variable mod

No comments:

Post a Comment