码迷,mamicode.com
首页 > 其他好文 > 详细

参数值传递

时间:2019-06-27 16:25:38      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:sys   work   赋值   pts   log   blog   class   eth0   传参   

方法实践

直接赋值方法

[root@clsn scripts]# vim bianliang.sh
# File Name: bianliang.sh
# Version: V1.0
# Author: clsn
# Organization: http://blog.znix.top
# Created Time : 2017-12-05 09:10:29
# Description:
##############################################################
name=CLSN
age=22
sex=Man
hobby=`ls`
ethFile=/etc/sysconfig/network-scripts/ifcfg-eth0

echo $hobby
ls $ethFile
[root@clsn scripts]# sh  bianliang.sh
bianliang.sh chanshu.sh clsn.sh clsn_test.sh panduan.sh quanju.sh xiugaizhuji.sh yhk.sh
/etc/sysconfig/network-scripts/ifcfg-eth0

传参 (传递参数)

[root@clsn scripts]# vim bianliang.sh
##############################################################
# File Name: bianliang.sh
# Version: V1.0
# Author: clsn
# Organization: http://blog.znix.top
# Created Time : 2017-12-05 09:10:29
# Description:
##############################################################
name=CLSN
age=22
sex=Man
hobby=$1
ethFile=$2

echo $hobby
ls $ethFile
[root@clsn scripts]# sh  bianliang.sh  clsn /etc/hostname 
clsn
/etc/hostname

交互式设置变量 read

[root@clsn scripts]# vim yhk.sh 
#!/bin/bash
##############################################################
# File Name: yhk.sh
# Version: V1.0
# Author: clsn
# Organization: http://blog.znix.top
# Created Time : 2017-12-04 17:01:44
# Description:
##############################################################
read -p  "请输入你的银行卡号:"  Yhk
read -s -p  "请输入密码:" miMa
echo
echo "你的银行卡号:"  $Yhk
echo "你的密码为:" $miMa
# 测试结果
[root@clsn scripts]# sh  yhk.sh 
请输入你的银行卡号:123456
请输入密码:
你的银行卡号: 123456
你的密码为: 123456

参数值传递

标签:sys   work   赋值   pts   log   blog   class   eth0   传参   

原文地址:https://www.cnblogs.com/zhangjiaqing/p/11097499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!