Aug 31, 2010

Further bash

Return value of a program
Try this
cd dada/ &> /dev/null/
echo return value : $?
cd &> /dev/null/
echo return value : $?
In ths program it will give a value as
If there is an error it will return 1 & if there is no error it will return value 0.
By this values we can make our program more user friendly.

Special things
To check if a variable is empty
-z s1
To chrck if a value is not empty
-n s1
Arithmetic relational operators
-lt - < -gt - >
-le - <= -ge - >=
-eq - ==
-ne - !=

$sed 's/to_be_replace/replaced/g' /file_path
eg :
$sed /s/name/Name/g' ~/user_details.t
This will read the "user_details.t" file in my home directory and it will replace the "name" keyword to "Name" and give the output on stdout.

$sed 12,18d /user_file.t
This will show all the line except 12 to 18.

$awk '/test/ {print}' ~/file.t
This will search the keyword test and print it.

$bc - a simple calculator
$bc -q [-q is to avoid the welcome screen]

No comments:

Post a Comment

Your comments are always welcome ...