Shell脚本学习总结(变量篇)
发布日期:2021-05-10 14:38:14 浏览次数:14 分类:精选文章

本文共 2756 字,大约阅读时间需要 9 分钟。

Shell������������������������

1. Shell���������

Shell������������������������������������������������������������������������Linux���������������������������������������������������������

2. Shell������������

���Linux������������������Shell������ (); - Bourne Shell (/usr/bin/sh) - Bourne Again Shell (/bin/bash) - C Shell (/usr/bin/csh) - K Shell (/usr/bin/ksh) - Shell for Root (/sbin/sh)

������#!/bin/sh���#!/bin/bash������������ Shell ������������������������

3.������Shell���������������

- ��������������������������������������������������������������� `chmod +x ./���������` ��������� `./���������` - Maher��������������������������������������������� `/bin/sh test.sh` ��� `/bin/bash test.sh`

������������������������������������������������������

4. Shell������

4.1 ������������������

- ��������������������������������������������������������������������������������� - ���������������������������������������������������������������bash��������������� <.debugLine> ��������������� ```bash city_name="������" #������������ for file in `ls /etc` #������������������ ``` ������������������������������������������������

4.2 ������������������

��������������������������� `$` ������������ < Ph��n t��ch ��������������� <_echo $city_name <_g/////////////////////
```bash city_name="������" echo $city_name echo ${city_name} ``` ������������������������������������������������������������������������

4.3 ������������

������ `unset` ������������ < Ph��n t��ch ��������� <_unset city_name ������������������������������������������������������ `readonly` ������

5. Shell ���������������

5.1 ������������������

< Ph��n��� ��������� - ������������������������������������������ - ������������������������������������������������������ - ������`str='This is a string!'`

5.2 ������������������

< Ph��n��� ��������� - ������������������������������������������ - ������`str="This is ${city_name}"`

5.3 ���������������������

- ������������������������`string="abcd" echo ${#string} # ������4` - ���������������`string="Hello World!" echo ${string:1:4} # ������ ello` - ���������������������`string="Hello World!" echo `expr index "$string" or` # ������5` - ������������������ ```bash city_name="������" greeting_1="Hello, "$city_name" !" greeting_2="Hello, ${city_name} !" echo $greeting_1 $greeting_2 ``` ���������������Hello, ������ ! Hello, ������ !

6. Shell ������

6.1 ������������������

```bash cities_name=("������" "������" "������") ``` ������������������������������`cities_name[0]`���@������������������

6.2 ������������������

```bash # ������������������ length=${#cities_name[@]} # ������������������������ lengthn=${#cities_name[n]} ```

������������������Shell������������������������������������������������������������������������������������

上一篇:Shell 脚本学习总结(传递参数篇)
下一篇:解决使用VS Code终端运行C++程序时,出现中文乱码现象.

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月11日 16时18分54秒