Bash: timed read input

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 [...]

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

Print color text in command line.

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, [...]

Posted in clear, printf, read, Text Manipulation | Hits: 169719 | 19 Comments »

read line by line

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 [...]

Posted in Bash, read | Hits: 47387 | 2 Comments »

Run multiple commands consequently

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 [...]

Posted in du, read, Symbol, terminator, while | Hits: 82833 | 5 Comments »