随笔分类 - shell
摘要:#! /usr/bin/perl$ans=max(2,18,3,5);print "Maximum value is $ans\n";sub max{ my $biggest=shift; foreach(@_){ $biggest=$_ if $_>$biggest; }return $biggest;}【说明】$_:当前参数@_:在子程序的调用过程中传值,perl使这些值可以在子程序中可用。
阅读全文
摘要:1 $$:显示PID编号[tandesir@localhost shell]$ echo $80682 $?:退出状态[tandesir@localhost shell]$ echo $?0[tandesir@localhost shell]$ ls test.txtls: 无法访问 test.txt: 没有那个文件或目录[tandesir@localhost shell]$ echo $?2[tandesir@localhost ~]$ true[tandesir@localhost ~]$ echo $?0[tandesir@localhost ~]$ false[tandesir@loc
阅读全文
摘要:运用select和case可以制作简单的交互式菜单。#! /bin/bashselect CHIOCE in show help exitdo case "$CHIOCE" in show) ls ;; help) echo "Help : This is a joke for test!" ;; exit) exit 0 ;; esacdone
阅读全文
摘要:【方法1】运用for in语句(1) bash#! /bin/bash
sum=0;
for i in {1..100}
do ((sum = sum + i))
done echo $sum
(2) perl#! /usr/bin/perl
$sum=0;
for ($i = 0; $i <=100 ; $i+=1)
{ $sum +=$i;
}
print "$sum\n";
【方法2】运用while语句(1) bash#! /bin/bash
i=0;
sum=0;
while [ "$i" -lt 100 ]
do ((i = i + ..
阅读全文
摘要:(1) vi bundle.sh#! /bin/bash#bundle :group files into distribution packageecho "# To unbundle, bash this file"for ido echo "echo $i 1>&2" echo "cat >$i <<'End of $i'" cat $i echo "End of $i"done(2) cat h1.txthello1hello2cat h2.txthello3
阅读全文
浙公网安备 33010602011771号