关于shell变量的第二个shell脚本
来源:互联网 发布:arp mac ip 编辑:程序博客网 时间:2024/05/22 14:06
#!/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
执行结果:
- 关于shell变量的第二个shell脚本
- 关于shell变量的第一个shell脚本
- 关于shell脚本变量的一些知识
- shell 第一个简单的脚本和变量
- 第二个shell程序------字符串变量操作
- shell脚本常用的变量
- shell脚本里的变量
- shell脚本的特殊变量
- Shell基础教程,什么是Shell?Shell脚本的执行方式,Shell中的变量,Shell中的特殊变量
- (2)第一个shell脚本和shell变量
- 【Shell脚本学习6】Shell变量:Shell变量的定义、删除变量、只读变量、变量类型
- 关于Shell脚本的二个位置参数
- 关于shell脚本编程的10个最佳实践
- 关于shell脚本编程的10个最佳实践
- 关于shell脚本编程的10个最佳实践
- 关于shell脚本编程的10个最佳实践
- 关于 shell 脚本编程的10 个最佳实践
- 关于shell脚本编程的10个最佳实践
- HDU 4348 To the moon
- 哈希表及处理冲突的方法
- 安卓开发颜色代码
- Codeforces Round #316 (Div. 2)
- #import与@class区别
- 关于shell变量的第二个shell脚本
- java常用API知识点总结
- Python3.X 抓取网络资源
- 1005. 继续(3n+1)猜想 (25)
- UIView
- 微信公众平台服务号如何申请
- 1Z0-053第一题
- 给定有序数组,创建高度最小的二叉查找树
- bash的配置文件以及加载的顺序