July 2014
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories

July 2014
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Function in shell script

Function in shell script DESCRIPTION: Function is the piece of code, which executed when we call. When thinking about the function in any computer language, three points comes in mind

1. Writing function code and calling that function when we need 2. Passing arguments to the function 3. Returning value from function

Next i […]

bash printf to variable

If you want to use bash’s printf formatting and store the value into a variable, you can use bash’s print’s -v flag as follows:

calc_elaspsed_time() { local SECONDS=$1 ((h=SECONDS/3600)) ((m=SECONDS%3600/60)) ((s=SECONDS%60)) printf -v ELAPSED_TIME “%02d:%02d:%02d” $h $m $s }

printf Command The built-in printf (print formatted) command prints a message to the screen. You […]