Category: Bash

Dividing in bash will cause problems if the result is below zero. This is a problem when you're trying to work out percentages. For example, if you simply want to divide 1 by 2 the result should be 0.5. However, bash returns the result 0: kieren@home:… more »

If a user presses control+c to exit your bash script you may wish for the script to preform some tasks before exiting. To do this just use the trap command. You can use trap along with a function to print a message to the user as follows: trap stopScr… more »

To read data that is coming from your COM port you need to know what the correct device is. Usually this is in /dev and is called something like /dev/ttyS0. To send data to the COM port simply redirect the output of an echo to the device: echo "ping 1… more »

Posted by Kieren Searle on the 04/14/08

Change the values of arguments

If you want to edit the value of an argument that looks something like the following: argument="value" It can be tricky if you don't know what "value" is. To solve this problem you can use the following sed command: sed 's/argument="[^"]*/argume… more »

Posted by Kieren Searle on the 04/10/08

How to exit a loop in bash

If you want to exit out of a loop but want the script to continue running from after the loop then you need to use the break statement; for (( i=0; i<5; i+=1 )) { if [[ $i -eq 3 ]] then break else echo "i: $i" fi } Output: i:… more »

1 2 >>

My name is Kieren and this is my blog. I use it mostly to document any solutions to problems I come across in computing.

Search

XML Feeds