Live Chat!

Bash: timed read input

* * * * * 2 votos

March 13th, 2007 mysurface

For some critical task, you just can’t wait for user response forever. If the user do not respond to input after certain period of time, you will use the default value and carry on the process. The bash command read have such capability to support that.
A simple example to illustrate how it works
answer=”yes”;read -p “Are [...]

Posted in Bash, read | Hits: 13609 | No Comments »

Print color text in command line.

* * * *   1 votos

December 24th, 2006 mysurface

Sometimes echo is not enough, if you need to print more advanced format of text. Lucky, we have printf. printf is a common function call in c programming language, if you learn c before, you should very familiar with this function.
Simply illustrate the power of printf, do as follow:
printf ‘\n\t\thello\tworld\n’
Besides readable character, printf can accept [...]

Posted in Text Manipulation, clear, printf, read | Hits: 25057 | 7 Comments »

read line by line

* * * * ½ 3 votos

October 18th, 2006 mysurface

When writting shell script, usually people are looking for how to read line by line and manipulate the lines, the simple way of using “read” shows as bellow
while read line
do
echo “__ $line”
done < file.txt
The example above simple add 2 underscore and a space infront of each line.
By default read is line by line, [...]

Posted in Bash, read | Hits: 8748 | 1 Comment »

Run multiple commands consequently

          0 votos

October 3rd, 2006 mysurface

By specified terminator ( ; ) like in C/C++ programming, you can run multiple commands consequently. We usually want to do this when we want to compile and install source code for certain packages.
./configure;make;make install
Bash first execute the configure, then make , consequently will install the package. But bare in mind, bash have no intelligent, [...]

Posted in Symbol, du, read, terminator, while | Hits: 14470 | 3 Comments »