当前位置:网站首页>Shell learning
Shell learning
2022-06-22 16:28:00 【The force is with you】
shell Study
Output hello world
// Designated for /bin/bash The interpreter under
#!/bin/bash
echo "Hello World !"
function shell There are two ways
1、 As an executable
chmod +x ./test.sh # Give the script permission to execute
./test.sh # Execute the script
2、 As interpreter parameters
// choose /bin/sh Interpreter execution under test.sh file
/bin/sh test.sh
shell The variable of
assignment :
name="test name"
Be careful name and = There must be no space between them
You can use statements to assign values to variables :
for file in `ls /etc` or for file in $(ls /etc)
Using variables :
${name}
A read-only variable :
readonly name
Delete variables :
unset name
Variable type :
local variable
environment variable
shell Variable
shell String
String assignment :
str='str' // Single quotation marks
str="str" // Double quotes
str=str // No quotes
Get string length :
string="abcd"
echo ${
#string} # Output 4
Extract substring :
string="runoob is a great site"
echo ${string:1:4} # Output unoo
Find substrings
string="runoob is a great site"
echo `expr index "$string" io` # Output 4
shell Pass parameters
echo "Shell Pass parameter instance !";
echo " File name of execution :$0";
echo " The first parameter is zero :$1";
echo " The second parameter is :$2";
echo " The third parameter is zero :$3";
Output
$ chmod +x test.sh
$ ./test.sh 1 2 3
Shell Pass parameter instance !
File name of execution :./test.sh
The first parameter is zero :1
The second parameter is :2
The third parameter is zero :3
shell Array
array_name=(value1 value2 ... valuen)
array_name[0]=value0
array_name[1]=value1
array_name[2]=value2
${array_name[index]}
echo " The elements of the array are : ${my_array[*]}"
echo " The elements of the array are : ${my_array[@]}"
shell Operator


边栏推荐
- 【山大会议】应用设置模块
- CUMT学习日记——数字图像处理考试速成笔记
- 二叉树练习第二弹
- SAP ABAP 中的模块化:宏、子程序和功能模块 -04
- '不敢去怀疑代码,又不得不怀疑代码'记一次网络请求超时分析
- Basic knowledge of audio and video | analysis of ANS noise suppression principle
- 使用stream api替代sql
- The odoo system sets priorities for the views independently developed by the original model
- Google Chrome small details
- SAP script tutorial: se71, se78, SCC1, vf03, so10-013
猜你喜欢

Dear students, don't read the textbooks any more. Just read this one for the complexity of time

首个赛博格人陨落背后:科技与渐冻症的极限赛跑

过气剧本杀,被露营“复活”

学习量子纠缠的可解释表示,该深度生成模型可直接应用于其他物理系统

SAP web service cannot log in to SOA management page with soamanager

POD 类型

机器学习笔记 - HaGRID—手势识别图像数据集简介

SAP ABAP dialog programming tutorial: module pool in -09

Process address space

SAP abap 数据类型,操作符和编辑器-02
随机推荐
The odoo system sets priorities for the views independently developed by the original model
odoo本地文档功能开发记录
【山大会议】WebRTC基础之用户媒体的获取
Conversion between numeric types and strings
SAP abap 数据类型,操作符和编辑器-02
机器学习笔记 - HaGRID—手势识别图像数据集简介
在JFlash中添加未知类型的单片机
Simulation of vector
直播无顶流:董宇辉这么火,还有人看刘畊宏吗?
[Shanda conference] establishment of webrtc tools for multi person video call
Basic knowledge of audio and video | analysis of ANS noise suppression principle
买网红雪糕的我,成了大冤种
【小程序项目开发-- 京东商城】uni-app开发之分包配置
ALV report in SAP tutorial - ABAP list viewer -012
天翼云乘风新基建,构建数字化转型“4+2”能力体系
6.gui (graphics, filling)
预约打新债到底安不安全呀?是不是靠谱的?
3. Classe abstraite (forme)
【山大会议】WebRTC基础之对等体连接
【山大会议】项目引入 Redux