shell 函数 参数调用 参数遍历 while循环
2014-04-16 09:57
204 查看
#!/bin/bash
#查找
function findit(){
if [ "$#" -lt 1 ] ; then #判断函数参数个数
echo "$#"
echo "Usage: findit filename"
return 1
fi
for loop #遍历调用函数的参数
#注意:这里是遍历函数的参数个数 不是外面调用shell的函数个数 但是下面是$* 会将shell 参数赋值给findif函数参数,如果要给函数传入特殊的值,我们可以用下面的 read -p "Please input the times of print you want: " n; 详细见 while循环
do
find $HOME -name $loop -print
done
return 0
}
findit $* //参数单个最多0-9 如果是2为必须用{} 比如{11} {12}等
function LoopPrint()
{
count=0;
while [ $count -lt $1 ]; //while循环 变量加1
do
echo $count $loop; //$loop是一个全局变量 上面那个函数的最后的值
let ++count;
sleep 1;
done
return 0;
}
read -p "Please input the times of print you want: " n;
LoopPrint $n;
#查找
function findit(){
if [ "$#" -lt 1 ] ; then #判断函数参数个数
echo "$#"
echo "Usage: findit filename"
return 1
fi
for loop #遍历调用函数的参数
#注意:这里是遍历函数的参数个数 不是外面调用shell的函数个数 但是下面是$* 会将shell 参数赋值给findif函数参数,如果要给函数传入特殊的值,我们可以用下面的 read -p "Please input the times of print you want: " n; 详细见 while循环
do
find $HOME -name $loop -print
done
return 0
}
findit $* //参数单个最多0-9 如果是2为必须用{} 比如{11} {12}等
function LoopPrint()
{
count=0;
while [ $count -lt $1 ]; //while循环 变量加1
do
echo $count $loop; //$loop是一个全局变量 上面那个函数的最后的值
let ++count;
sleep 1;
done
return 0;
}
read -p "Please input the times of print you want: " n;
LoopPrint $n;
相关文章推荐
- shell的一些常用的语句(if语句,变量,for、while、until语句、函数调用、脚本调用)
- shell脚本中实现脚本a里面的函数调用脚本b中的函数参数-用到source关键字
- c++ 函数调用在进入下一个循环的时候会再次初始化参数,将函数体直接写进去就正常
- SHELL循环遍历两个日期作为参数执行命令
- linux中的for、while循环输出中赋值变量及shell中循环获取脚本参数
- c++ 函数调用在进入下一个循环的时候会再次初始化参数,将函数体直接写进去就正常
- shell自定义函数及参数调用解析
- shell中两个函数(带参数)相互调用
- Shell脚本通过参数传递调用指定函数
- shell(2):shell中关于if,while,输入参数,函数,c++进程等相关知识应用汇集事例
- shell基础之四:函数、死循环及for,while特殊用法
- shell自定义函数及参数调用解析
- SHELL循环遍历两个日期作为参数执行命令
- tar ,cpio打包解压. shell脚本for,while,until循环. rpm包管理,select循环菜单,函数function,yum
- Shell for&while 循环详细总结
- 简化函数调用之六 :Replace Parameter with Explicit Methods(以明确函数取代参数)
- python 如何调用带参数的shell脚本
- Delphi中调用C约定不定参数函数的调用方法.
- shell脚本学习总结10--系统函数调用
- Lisp语言:函数的定义,调用以及参数的传递