Tuesday, November 19, 2013

Bash Scripting Introduction

Hi all, Today we gonna learn about bash scripting.
what is bash scripting?
as linux user, we often hear about bash scripting.
script is a set of command that had function to help us. Bash script is a set of command bash. With this bash scripting, we can create a program to help us create an application.
for example, let use see script below.
echo “===================”
echo “Today date is” `date`
echo “Totatl Usage Our computer:”
df -h
then we save this file with name cekusage.sh.
to run this command, there 2 way:
1. ussing command sh.
for example:
sh cekusage.sh
there are some disadvantage using this command that is this command will disable reading from stdin that comes from script and make the script ineffective.
2. using command chmod to change permission in file so we can execute the script .
chmod 555 cekusage.sh (change permission into read and execute for user,group and other).
after that we can use command ./cekusage.sh
what is sha-bang?
sha-bang is header in script that we created. For example #!/bin/bash
In the basic, syntax from sha-bang is
#! path bin that we used
example path: /bin/bash, /bin/sh, /sbin, etc
The use for sha-bang is command interpreter. For analogy, shabang is recognition to script. Shabang had a function to describe which langguage that we use and the command location.
for common use /bin/sh is more popular in UNIX family, In Linux Family is more common using /bin/bash. If we want to use command in UNIX family, we can use sha-bang /bin/sh.


Post a Comment