Friday, November 22, 2013

Simple I/O with bash scripting

I/O is a based of computer work because this capacity make computer so power.
I/O is a device that handle input and output, both for keyboard, floppy, monitor screen, etc. 
beside echo, we can use printf command to print out with output standard, in screen or in file with specific format.

below this example:


printf "Hi, use printf ala C\n\t\a in bash\n";
printf "My url %s\n %d decimal = %o octal\n" $url $number $number;
printf "%d decimal in float = %.2f\n" $number $number

and below is the result

Hi, use printf ala C
    in bash
My url
32 decimal = 40 octal
32 decimal in float = 32.00

below it the table for the format control

Format controlinformation
%ddata integer format
%ffloat atau decimal

Input with read

after echo and printf for output process, now we will use command read.
this command very good to read or accept input from standard input

below is the example


echo -n "Your name :"
read name;

echo    "Hi $name,  How are you?";
echo    "message and reply :";
echo    "said $name, $REPLY";

below is the result

Your name : elvin
Hi elvin, How are you?
message and reply :
i'm fine. thanks
said elvin, i'm fine. thanks


Post a Comment