关于shell变量的第二个shell脚本
2015-08-22 19:55
661 查看
1.文件名为test.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1
执行
sh test.sh
执行结果:
My name is hanyanwei
0
/root
#####################
test.sh
2.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1
执行
sh var.sh lkp
执行结果:
My name is hanyanwei
0
/root
#####################
var.sh
lkp
3.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1 $2
执行
sh var.sh parameter1 parameter2
执行结果:
My name is hanyanwei
0
/root
#####################
var.sh
parameter1 parameter2
4.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1 $2
执行
sh var.sh 123 abc
执行结果:
My name is hanyanwei
0
/root
#####################
var.sh
123 abc
5.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo "#####################"
echo "The \$1 is $1"
echo "The \$2 is $2"
echo "The \$? is $?"
echo "The \$* is $*"
echo "The \$# is $#"
执行
sh var.sh
执行结果:
#####################
The $1 is
The $1 is
The $1 is 0
The $1 is
The $1 is 0
6.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo "#####################"
echo "The \$1 is $1"
echo "The \$2 is $2"
echo "The \$? is $?"
echo "The \$* is $*"
echo "The \$# is $#"
执行
sh var.sh abc edf
执行结果:
#####################
The $1 is abc
The $1 is edf
The $1 is 0
The $1 is abc edf
The $1 is 2
$?的讲解
如上图:
我第一次输入执行: kdfjsdklfsd
会提 command not found
然后我再执行echo $?
结果是127
注解:127是错误码
然后我在执行: df -f
然后我再执行:echo $?
结果是0
注解:0表示程序执行成功了
只要返回值是 0,就代表程序执行成功了~
7.文件名为var1.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo -e "\033[32m---------------------------\033[0m"
echo "This is $0 param !"
echo "This \$1 is $1 param !"
echo "This \$2 is $2 param !"
echo -e "\033[32m---------------------------\033[0m"
echo "This \$* is $* param !"
echo "This \$# is $# param !"
echo "This \$? is $? param !"
执行
sh var1.sh abc edf
执行结果:
8.文件名为var2.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo -e "\033[32mPlease select Menu follow:\033[1m"
echo "1)安装apache服务器."
echo "2)安装Mysql服务器."
echo "1)安装php服务器."
echo "1)安装LAMP WEB架构."
echo "-----------------------------------------"
执行
sh var2.sh
执行结果:
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1
执行
sh test.sh
执行结果:
My name is hanyanwei
0
/root
#####################
test.sh
2.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1
执行
sh var.sh lkp
执行结果:
My name is hanyanwei
0
/root
#####################
var.sh
lkp
3.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1 $2
执行
sh var.sh parameter1 parameter2
执行结果:
My name is hanyanwei
0
/root
#####################
var.sh
parameter1 parameter2
4.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
name=hanyanwei
echo "My name is $name"
echo $UID
echo $PWD
echo "#####################"
echo $0
echo $1 $2
执行
sh var.sh 123 abc
执行结果:
My name is hanyanwei
0
/root
#####################
var.sh
123 abc
5.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo "#####################"
echo "The \$1 is $1"
echo "The \$2 is $2"
echo "The \$? is $?"
echo "The \$* is $*"
echo "The \$# is $#"
执行
sh var.sh
执行结果:
#####################
The $1 is
The $1 is
The $1 is 0
The $1 is
The $1 is 0
6.文件名为var.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo "#####################"
echo "The \$1 is $1"
echo "The \$2 is $2"
echo "The \$? is $?"
echo "The \$* is $*"
echo "The \$# is $#"
执行
sh var.sh abc edf
执行结果:
#####################
The $1 is abc
The $1 is edf
The $1 is 0
The $1 is abc edf
The $1 is 2
$?的讲解
如上图:
我第一次输入执行: kdfjsdklfsd
会提 command not found
然后我再执行echo $?
结果是127
注解:127是错误码
127是命令没找到,command not found
然后我在执行: df -f
然后我再执行:echo $?
结果是0
注解:0表示程序执行成功了
只要返回值是 0,就代表程序执行成功了~
7.文件名为var1.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo -e "\033[32m---------------------------\033[0m"
echo "This is $0 param !"
echo "This \$1 is $1 param !"
echo "This \$2 is $2 param !"
echo -e "\033[32m---------------------------\033[0m"
echo "This \$* is $* param !"
echo "This \$# is $# param !"
echo "This \$? is $? param !"
执行
sh var1.sh abc edf
执行结果:
8.文件名为var2.sh
#!/bin/bash
#define path variables
#by authors lkp 2015-08-22
echo -e "\033[32mPlease select Menu follow:\033[1m"
echo "1)安装apache服务器."
echo "2)安装Mysql服务器."
echo "1)安装php服务器."
echo "1)安装LAMP WEB架构."
echo "-----------------------------------------"
执行
sh var2.sh
执行结果:
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- Ruby中的变量学习总结
- shell字符串操作详解
- 详解Lua中的变量相关知识点
- Shell中删除某些文件外所有文件的3个方法
- Ruby中执行Linux shell命令的六种方法详解
- dos批处理文件中的变量小结
- VB使用shell函数打开外部exe程序的实现方法
- Shell编程的一些知识集合
- Shell中的for和while循环详细总结
- 探索PowerShell(七) PowerShell变量
- VBScript教程 第四课VBScript变量
- 什么是Shell?Shell脚本基础知识详细介绍
- Shell脚本中引用、调用另一个脚本文件的2种方法
- 关于SQL 存储过程入门基础(基础知识)
- perl 变量 $/ 的用法解析 上下文为行模式时,$/ 定义以什么来区分行