交互式输入输出程序实例

来源:互联网 发布:怎么注册淘宝客 编辑:程序博客网 时间:2024/05/23 00:10

交互式输入输出程序演练:


Shell实例1

[root@ChangerLee顺序结构]#cat read-echo.sh

#!/bin/bash

#readecho的配合实例


echo-e "接受输入输出IP地址\t:"

readipaddr

echo"my ip address is $ipaddr"

[root@ChangerLee顺序结构]#sh read-echo.sh

接受输入输出IP地址 :

192.168.1.1

myip address is 192.168.1.1

[root@ChangerLee顺序结构]#cat read-echo1.sh

#!/bin/bash

#接收输入并且输出


now_time=`date+%F,%H:%M:%S`

read-p "plz input your username:" username

read-p "plz input your password:" password

password_md5=$(echo$password|md5sum|awk '{print $1}')

echo-e "${now_time}\n系统为你生成用户名:$username,密码为:$password_md5"

Shell实例2


[root@ChangerLee顺序结构]#sh read-echo1.sh

plzinput your username:ChangerLee

plzinput your password:bkb

2016-08-06,11:19:50

系统为你生成用户名:ChangerLee,密码为:c569b9989319c725420a4f7e5fcf20d7


Shell实例3

[root@ChangerLee顺序结构]#cat read-echo2.sh

#!/bin/bash

#时间输出文件

test$# -eq 2

if [$? -eq 0 ]

then

#fileyour select exists!!!

test-f $1

if[ $? -eq 0 ]

then

echo"文件${1}存在"

else

touch${1}

echo-e "文件${1}不存在\n系统已经为你创建:`ls${1}`"

fi

test-f $2

if[ $? -eq 0 ]

then

echo"文件${1}存在"

else

touch${2}

echo-e "文件${2}不存在\n系统已经为你创建:`ls${2}`"

fi


#putsystime to flie your select

echo"`date +%F\ %H-%M-%S`">$1

echo"`date +%F\ %H-%M-%S`">$2

echo"$1:`cat $1`"

echo"$2:`cat $2`"

else

echo"Just need two argument!!!"

fi

[root@ChangerLee顺序结构]#sh read-echo2.sh file file1

文件file不存在

系统已经为你创建:file

文件file存在

file:2016-08-0612-04-23

file1:2016-08-0612-04-23


0 0
原创粉丝点击