当前位置:网站首页>shell学习
shell学习
2022-06-22 15:10:00 【原力与你同在】
输出hello world
// 指定用/bin/bash下的解释器来执行
#!/bin/bash
echo "Hello World !"
运行shell有两种方法
1、作为可执行程序
chmod +x ./test.sh #使脚本具有执行权限
./test.sh #执行脚本
2、作为解释器参数
// 选用/bin/sh下的解释器执行 test.sh文件
/bin/sh test.sh
shell的变量
赋值:
name="test name"
注意name和=之间不能有空格
可以使用语句给变量赋值:
for file in `ls /etc` 或 for file in $(ls /etc)
使用变量:
${name}
只读变量:
readonly name
删除变量:
unset name
变量类型:
局部变量
环境变量
shell变量
shell的字符串
字符串赋值:
str='str' // 单引号
str="str" // 双引号
str=str // 无引号
获取字符串长度:
string="abcd"
echo ${
#string} #输出 4
提取子字符串:
string="runoob is a great site"
echo ${string:1:4} # 输出 unoo
查找子字符串
string="runoob is a great site"
echo `expr index "$string" io` # 输出 4
shell传递参数
echo "Shell 传递参数实例!";
echo "执行的文件名:$0";
echo "第一个参数为:$1";
echo "第二个参数为:$2";
echo "第三个参数为:$3";
输出
$ chmod +x test.sh
$ ./test.sh 1 2 3
Shell 传递参数实例!
执行的文件名:./test.sh
第一个参数为:1
第二个参数为:2
第三个参数为:3
shell数组
array_name=(value1 value2 ... valuen)
array_name[0]=value0
array_name[1]=value1
array_name[2]=value2
${array_name[index]}
echo "数组的元素为: ${my_array[*]}"
echo "数组的元素为: ${my_array[@]}"
shell运算符


边栏推荐
- [VTK] model rotation and Translation
- 华为云HCDEZ专场暨分布式技术峰会:华为云分布式云原生技术与实践之路
- Pymssql Module User Guide
- SAP ABAP 对话框编程教程:中的模块池-09
- [Shanda conference] acquisition of user media based on webrtc
- 天翼云乘风新基建,构建数字化转型“4+2”能力体系
- 【山大会议】WebRTC基础之用户媒体的获取
- 浙江创投圈的“半壁江山”,还得是国资
- [Shanda conference] peer connection based on webrtc
- Huawei cloud hcdez special session and Distributed Technology Summit: Huawei cloud distributed cloud native technology and Practice
猜你喜欢

Focus on creating a net red product. The xinjietu x70s is newly launched, starting from 87900

SAP ABAP 数据字典教程 SE11:表、锁定对象、视图和结构 -03

Program substitution function

84.(cesium篇)cesium模型在地形上运动

二叉树练习第二弹

北京恢复堂食半月记:如何重燃门店经营烟火气

SAP abap 数据类型,操作符和编辑器-02

Odoo local document function development record

SAP ABAP 中的 Smart Forms-014

音视频基础知识|ANS 噪声抑制原理解析
随机推荐
【山大会议】应用设置模块
畅享高性能计算!天翼云HPC解决方案来了
数睿数据深度 | 关于软件自主可控,源代码向左,无代码向右
Batch export excel zip using zipfile, openpyxl and flask
SAP ABAP 中的用户出口和客户出口-015
过气剧本杀,被露营“复活”
Default function control =default and =delete
Simulation of vector
数值类型和字符串之间的转换
二叉树练习第二弹
【山大会议】WebRTC基础之用户媒体的获取
SAP教程中的ALV报告 - ABAP列表查看器-012
pymssql模块使用指南
Wechat applet avatar pendant production
Runtime -- explore the nature of classes, objects, and classifications
SAP ABAP 子屏幕教程:在 SAP 中调用子屏幕-010
6.gui (graphics, filling)
Pymssql Module User Guide
How to embody the value of knowledge management in business
POD 类型