linux shell script 例子1
1. 如何获得脚本参数:
#!/bin/she
#
while [ -n "$1" ]
do
case "$1" in
-a) echo "found the -a option";;
-b) param="$2"
echo "found the -b option";;
-c) echo "found the -c option";;
--) shift
break;;
*) echo "$1 is not an option";;
esac
shift
done
count=1
for para in "#@"
do
echo "parameter #$count : $para"
count=$[ $count + 1 ]
done
2.判断输入是否符合条件:
#!/bin/sh
#
read input
if [[ $input == r* && ${#input} -eq 10 ]]; then #check the input character bits
echo "yes, your input right."
else
echo "no ,your input error."
fi
3.如何让用户输入,如果你想得到用户输入一定要记得read command.
#!/bin/sh
#
#
read -n1 -t 10 -p "Do you want to continue [Y/N]?" answer
case $answer in
Y | y) echo
echo "fine, continue on ... ";;
N | n) echo
echo "ok, goodbye
exit;;
esac
echo "this is the end of the script"
4.从文件中读出数据
#!/bin/sh
#
#
#
count=1
cat testfile | while read line
do
echo "Line $count : $line"
count=$[ $count + 1 ]
done
echo "finished processing the file"
#you can also use the read command to read data stored in a file on the linux system. each call to the read command reads a single line of text from the file. when there are no more lines left in the file,the read command will exit with a non-zero exit status.
5.创建自己的重定向文件描述符
#!/bin/bash
# storing STDOUT, then coming back to it
exec 3>&1
exec 1>test14out
echo "This should store in the output file"
echo "along with this line."
exec 1>&3
echo "Now things should be back to normal"
#This example is a little crazy, so let’s walk through it piece by piece. First, the script redirects file descriptor 3 to the current location of file descriptor 1, which is STDOUT. This means that any output sent to file descriptor 3 will go to the monitor.The second exec command redirects STDOUT to a file. The shell will now redirect any output se
相关文档:
一、用vi filename打开文件:
二、基本知识:vi 可以分三种状态:命令模式(command)、插入模式(insert)和末行模式(last line)
(1)命令模式:打开文件时默认是命令模式,控制屏幕光标的移动、字符、字或者行的删除,移动 &nb ......
我用的是Centos5.4 DVD光盘安装的linux操作系统,安装linux的时候选上开发工具,Xmanager,与数据库相关的包。
操作系统安装完成之后需要进行一系列的配置才能安装oracle10g,下面把主要步骤记录下来。
1.安装完操作系统之后还是有些包没有安装,然而安装oracle10g的时候需要用到,没有安装的包有:
libXp-1.0.0-8.i386.rp ......
Technorati 标签: linux,at 名称 : at
使用权限 : 所有使用者
使用方式 : at -V [-q queue] [-f file] [-mldbv] TIME
说明 : at 可以让使用者指定在 TIME 这个特定时刻执行某个程式或指令,TIME 的格式是 HH:MM其中的 HH 为小时,MM 为分钟,甚至你也可以指定 am, pm, midnight, noon, teatime(就是下午 4 点锺 ......
1.MySQL简介
MySQL是一个广泛使用的结构化查询语言(SQL)数据库服务器。和其他SQL服务器一样,MySQL提供了访问和管理SQL数据库的方法,但是,MySQL同时也提供了创建数据库结构以及在这些结构中添加、修改和删除这些结构的工具。
MySQL数据库相关的软件包主要有以下几种:
......