Linux中的shell有多种类型,其中最常用的几种是Bourne shell(sh)、C shell(csh)和Korn shell(ksh)。三种shell各有优缺点。Bourne shell是UNIX最初使用的shell,并且在每种UNIX上都可以使用。Bourne shell在shell编程方面相当优秀,但在处理与用户的交互方面做得不如其他几种shell。Linux操作系统缺省的shell是Bourne Again shell,它是Bourne shell的扩展,简称Bash,与Bourne shell完全向后兼容,并且在Bourne shell的基础上增加、增强了很多特性。Bash放在/bin/bash中,它有许多特色,可以提供如命令补全、命令编辑和命令历史表等功能,它还包含 了很多C shell和Korn shell中的优点,有灵活和强大的编程接口,同时又有很友好的用户界面。……【阅读全文】
Monthly Archives: 11月 2011
在Perl中使用Term::ANSIColor模块控制颜色的三种方法
-
方法一
Term::ANSIColor的函数color有以下参数:
clear, reset, dark, bold, underline, underscore, blink, reverse, concealed, black, red, green, yellow, blue, magenta, cyan, white, on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, and on_white
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #!/usr/bin/perl use Term::ANSIColor; print color "red"; print "REDn"; print color "green"; print "GREENn"; print color "bold blue"; print "BOLD BLUEn"; print color "on_yellow"; print "ON YELLOWn"; print color "on_cyan"; print "ON CYANn"; print color "reset"; |
在Shell脚本中显示进度条
注意:如果你使用的是Ubuntu,第一行中的程序路径一定要写/bin/bash而不是/bin/sh;其他版本的两者皆可,因为/bin/sh只是/bin/bash的一个软链接;在Ubuntu中/bin/sh是/bin/dash的软链接。
-
方法一
1 2 3 4 5 6 7 8 9 10 | #!/bin/bash b='' for ((i=0;$i<=100;i+=2)) do printf "progress:[%-50s]%d%%r" $b $i sleep 0.1 b=#$b done echo |
在Perl程序中显示进度条之多姿多彩的自写代码
-
方法一
1 2 3 4 5 6 7 8 | #!/usr/bin/perl my $max = 10; for ( 1 .. $max ) { my $percent = $_ / $max * 100; print "$_ - $percent % OK!n"; sleep(1); } |
方法二
从“…..”的长度来判断进度。
1 2 3 4 5 6 7 8 9 | #!/usr/bin/perl -w $| = 1; my $max = 10; for ( 1 .. $max ) { print "."; print " Complete!n" if ( $_ == $max ); sleep(1); } |
-
方法三
用滚轮在原地显示进度,当然也可以加入百分比。
1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/perl -w local $| = 1; my @progress_symbol = ( '-', '', '|', '/' ); my $n = 0; for ( my $i = 1 ; $i <= 100 ; $i++ ) { print "r $progress_symbol[$n] $i"; $n = ( $n 》= 3 ) ? 0 : $n + 1; select( undef, undef, undef, 0.1 ); } print "n"; local $| = 0; |
在Perl程序中显示进度条之使用Acme::ProgressBar模块
db7fa1ad10a8a31ff9ea5460004e9d28006……【阅读全文】
在Perl程序中显示进度条之使用Term::ProgressBar模块
-
A really simple use
-
A smoother bar update
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #!/usr/bin/perl -w use Term::ProgressBar 2.00; use constant MAX =》 100_0000; my $progress = Term::ProgressBar-》new(MAX); for ( 0 .. MAX ) { my $is_power = 0; for ( my $i = 0 ; 2**$i 《= $_ ; $i++ ) { $is_power = 1 if 2**$i == $_; } if ($is_power) { $progress-》update($_); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/usr/bin/perl -w use Term::ProgressBar 2.00; my $max = 100000; my $progress = Term::ProgressBar-》new($max); for ( 0 .. $max ) { my $is_power = 0; for ( my $i = 0 ; 2**$i 《= $_ ; $i++ ) { $is_power = 1 if 2**$i == $_; } $progress-》update($_); } |
在Perl程序中显示进度条之使用Smart::Comments模块
-
简单的演示
db7fa1ad10a8a31ff9ea5460004e9d28009……【阅读全文】
程序代码中的缩进与大括号风格
-
K&R style
Named after Kernighan & Ritchie, because the examples in K&R are formatted this way. Also called `kernel style’ because the Unix kernel is written in it, and the `One True Brace Style’ (abbrev. 1TBS) by its partisans. In C code, the body is typically indented by eight spaces (or one tab) per level, as shown here. Four spaces are occasionally seen in C, but in C++ and Java four tends to be the rule
rather than the exception.……【阅读全文】
又一个跨平台的网络云存储与同步服务
前面有两篇文章介绍跨平台的网络云存储、同步、备份软件或服务:……【阅读全文】