output=""
base_array=({1..49})
length=${#base_array[@]}
argument=$1
howmany=${argument:-6}
usage="Usage:\t${0##*/} [[option] number of picks](default 6)"
message_to_user="Number of picks should not be greater than $length"
out_of_range=66
non_numberic_argument=65
if [[ $howmany =~ [^0-9]+ ]]
then
echo -e "$usage" >&2 ; exit $non_numberic_argument
elif [ $howmany -gt $length ]
then
echo "$message_to_user" >&2 ; exit $out_of_range
fi
for (( i=1 ; i<=howmany ; i++ ))
do
pick=${base_array[$(( RANDOM % length ))]}
output="$output $pick"
resize_array=($(echo ${base_array[@]} | sed "s/\<$pick\>//"))
base_array=(${resize_array[@]})
length=${#base_array[@]}
done
die "Number of picks should not be greater than $length\n" if ($howmany > $length) ;
die "Usage:\t$0 [[option]number of picks](default 6)\n" if ($howmany =~ /\D+/) ;
$howmany = 6 if (@ARGV == 0) ;
$ cat bin/free
#! /usr/bin/ruby
# roustic free for cygwin, ruby version
class PrintHeader
def initialize(i="total", j="used", k="free")
@a = i
@b = j
@c = k
end
def header
print "\t", @a, "\t", @b, "\t", @c, "\n"
end
end
n = PrintHeader.new("總數", "已用", "剩餘")
n.header
filename = "/proc/meminfo"
file = open(filename)
while text = file.gets
if text =~ /Mem:|Swap:/
str = [ text.split(/\s+/) ]
step = 1024 * 1024
str.each { |i|
j = i[0]
a = i[1].to_i / step.to_i
b = i[2].to_i / step.to_i
c = i[3].to_i / step.to_i
print j, "\t", a," M", "\t", b," M", "\t", c," M", "\n"
}
end
end
Originally posted by dnntgmfd at 2009-5-31 10:39:
#include <iostream.h>
void main()
{
int a=0,b=0;
for(a=0,a++,a<100)
b=b+1;
cout<<b<<endl;
}
好久没用了,也不知道对了没有,
另外这算不算是这规表达式呢?