shell脚本
墨非牵念
十年为一剑出鞘始见锋
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
shell脚本:test
test语句实例:#! /bin/shif [ -f /bin/bash ]then echo "file /bin/bash exits"fiif [ -d /bin/bash ]then echo "file /bin/bash is a directory"else echo "file /bin/bash is not a directory"fi原创 2013-06-15 14:10:41 · 735 阅读 · 0 评论 -
shell脚本:and和or
#! /bin/shtouch file_onerm -f file_twoif [ -f file_one ] && echo "hello " && [ -f file-two ] && echo "world"then echo "in if"else echo "in else"fiand语句和or语句常常一起使用,and语句是当前一个语句为真的时候,才原创 2013-06-15 14:32:19 · 8561 阅读 · 0 评论 -
shell脚本:here
here文档是传输给shell脚本的一种方式,示例如下:#! /bin/shcat <<hellohellolmyname is good comehello原创 2013-06-15 19:39:47 · 647 阅读 · 0 评论 -
shell脚本:trap
trap是对信号的处理,可以定义shell接收到哪个信号时,执行相应的操作。示例如下:#! /bin/shtrap "rm -f /tmp/my_file" INTecho creating file "/tmp/my_file"date > /tmp/my_fileecho press ctrl+cwhile [ -f /tmp/my_file ]do echo exist原创 2013-06-15 19:30:56 · 721 阅读 · 0 评论 -
shell脚本:shift
使用该命令可以让所有的参数变量左移一位。#! /bin/shwhile [ "$1" != " " ]do echo "$1" shiftdone原创 2013-06-15 19:28:48 · 557 阅读 · 0 评论 -
shell脚本:set
set指令的作用是为shell设置参数变量,用法如下:#! /bin/shecho the date is $(date)set $(date)echo the mouth is $2exit 0原创 2013-06-15 19:26:27 · 1185 阅读 · 0 评论 -
shell脚本:函数使用
函数使用示例:#! /bin/shyes_or_no() { echo "is your name $*" while true do echo -n "Enter yes or no" read x case "$x" in y|yes) return 0;; n|no) return 1;; *) return原创 2013-06-15 14:39:53 · 464 阅读 · 0 评论 -
shell脚本:while语句
当不知道要循环多少次时,需要使用while语句:#! /bin/shread foowhile [ $foo != "123456" ]do echo $foo read foodone原创 2013-06-15 14:27:48 · 708 阅读 · 0 评论 -
shell脚本:if语句
if语句相对简单,是一组控制语句,应用如下:#! /bin/shecho -n "is moring? yes or no : "read textif [ "$text" = "yes" ]then echo "goodmorning!"elif [ $text = "no" ]then echo "goodafter!"else echo "please inp原创 2013-06-15 14:16:23 · 563 阅读 · 0 评论 -
Linux下静态库制作
Linux下静态库制作:1.首先,为两个函数分别创建各自的源文件:#include void find(int a){printf("fing a num %d",a);}第二个:#include void rea(char *str){printf("rea:%s",str);}2.分别编译函数生成 .o 文件, gcc -c原创 2013-06-15 14:05:35 · 421 阅读 · 0 评论 -
shell脚本:dialog
dialog是在shell中实现图形化界面的一种方式,#! /bin/shdialog --title "Question" --msgbox "welcom to our home" 9 18dialog --title "good" --yesno "Are you coming?" 9 18if [ $? != 0 ]then dialog --infobox "thank原创 2013-06-15 19:45:30 · 762 阅读 · 0 评论 -
shell脚本:export
使用export可以将变量导入到shell中,示例如下:先写export2;#! /bin/shecho "$foo"echo "$bar"再写export1:#! /bin/shfoo="the first "export bar="the second"./export2.sh原创 2013-06-15 19:23:45 · 977 阅读 · 0 评论 -
shell脚本:for语句
for语句做循环处理,处理的值可以为任意值,示例如下。#! /bin/shfor foo in baf fing 45do echo $foodone在循环中会一次输出所有字符串,如果要一次输出,需要添加 “”当需要使用其他命令时,示例如下:#! /bin/shfor file in $(ls f*.sh)do echo $filedone程序中会使用ls原创 2013-06-15 14:23:33 · 573 阅读 · 0 评论
分享