Tuesday, March 12, 2013

Making loops in shell script


(1)
for i in $(seq 1 10)
do 
 echo $i
 //do some stuff
done

(2)
for i in `seq 1 10`
do
 //do some stuff
done

(3)
for i in 1 2 3 4 5 6 7 8 9 10
do
 //do some stuff 
done
 
(4) 
for i in {1..10} {15..20}
do //do some stuff
done

(5)
s=0
while [ "$s" -lt 10 ]; do s=`echo $s+1|bc`; echo $s; done

(6)
for (( i=1; c<=10; i++ ))
do
 // do some stuff
done
 
(7) Loops through files in a directory
files=( $( ls /path/to/directory ) )  #list files in an array
n=${#files[*]}   #array size
for (( i=0; i < n; i++ ))
do 
 echo File number $((i+1)) is ${files[$i]}
done

Wednesday, April 11, 2012

With Fortran, how to overwrite the present line on the console screen?

program print_on_the_same_line

integer :: I, N

N=5

open(6,CARRIAGECONTROL ='FORTRAN')

do I=1,N
call sleep(1)
write(6,'(1H+" ",I,a,I)') I,' out of',N
enddo

close(6)

stop
end program

****************************************************
The above Fortran codes are adopted from the link:
http://stackoverflow.com/questions/1390125/how-do-i-format-a-print-or-write-statement-to-overwrite-the-current-line-on-the

Sunday, March 11, 2012

Using an old router as a wireless Access Point

For convenience, we call, in this note, the present router as master router, and the old router as AP.

Firstly, assume the master router has been configured with the following settings:
LAN IP: 192.168.0.1
Subnet Mask: 255.255.255.0
DHCP Server: Yes
UPnP: On
Wireless SSID and security mode: set up according to router manual

Before connecting the master router and AP, configure the AP with settings:
LAN IP: within subnet of master router such as 192.168.0.2
Subnet Mask: 255.255.255.0
DHCP Server: No
UPnP: Off
Wireless SSID and security mode: the same as that of the master router

Finally, connect the master router and the AP via LAN port to LAN port directly and leave the WAN port of the AP disconnected.
Rebooting one or both devices maybe necessary to take effect the configurations.