当前位置:网站首页>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运算符


边栏推荐
- Navicat premium connecting to Oracle database (Graphic tutorial)
- 19、 Xv6 context switching (implementation of context switching; encapsulation and recovery of state machine)
- SAP web service 无法使用 SOAMANAGER 登陆到SOA管理页面
- SAP价值流程&帮助请求流程-011
- CMake教程系列-00-简介
- Swift -- 保存打印日志到沙盒
- 音视频基础知识|ANS 噪声抑制原理解析
- Turn to: jackwelch: strategy is to think less and be quick to act
- 3.抽象类(shape)
- Jenkins automatically triggers compilation by checking code submissions
猜你喜欢

SLAM十四讲之第6讲--非线性优化

数睿数据荣获第二届ISIG中国产业智能大会两项年度大奖

Adding an unknown type of MCU to jflash

Bridging the gap between open source databases and database services

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

数值类型和字符串之间的转换

Runtime -- explore the nature of classes, objects, and classifications

Linux安装mysql

odoo系统对原有模型单独开发的视图设置优先级

Static assertion static_ assert
随机推荐
期货怎么开户?网上期货开户安全吗?
5.文件的读写(学生类)
84. (cesium chapter) movement of cesium model on terrain
Simulation of vector
Uni develops wechat applet to customize automatic camera detection (portrait + ID card)
Default function control =default and =delete
Discover the number of media new users can insert
School enterprise alliance is on the way! Huawei cloud gaussdb has come to universities again
【山大会议】WebRTC基础之用户媒体的获取
What is the relationship between CSC securities and qiniu school? Is it safe to open a securities account
直播无顶流:董宇辉这么火,还有人看刘畊宏吗?
odoo部署到服务器并配置为服务
预约打新债到底安不安全呀?是不是靠谱的?
mysql - sql执行过程
【山大会议】一些基本工具类定义
Deploy odoo to the server and configure it as a service
Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance
find命令使用
How to embody the value of knowledge management in business
Runtime——探索类,对象,分类本质