Shell | Hello World

简介: Shell | Hello World

输出语句


使用 chmod 命令给文件hello.sh 添加可执行权限 x

[root@VM-0-9-centos data]# echo "hello world"
hello world
[root@VM-0-9-centos data]# vi hello.sh
[root@VM-0-9-centos data]# ls
C_language  hello.js  hello.sh  server.js
[root@VM-0-9-centos data]# ./hello.sh
-bash: ./hello.sh: 权限不够
[root@VM-0-9-centos data]# ll
总用量 16
drwxr-xr-x 2 root root 4096 12月 30 14:18 C_language
-rw-r--r-- 1 root root   29 12月 30 14:38 hello.js
-rw-r--r-- 1 root root   19 12月 30 15:30 hello.sh
-rw-r--r-- 1 root root  410 12月 30 14:42 server.js
# 使用 chmod 给文件hello.sh 添加可执行权限 x 
[root@VM-0-9-centos data]# chmod +x ./hello.sh
[root@VM-0-9-centos data]# ll
总用量 16
drwxr-xr-x 2 root root 4096 12月 30 14:18 C_language
-rw-r--r-- 1 root root   29 12月 30 14:38 hello.js
-rwxr-xr-x 1 root root   19 12月 30 15:30 hello.sh
-rw-r--r-- 1 root root  410 12月 30 14:42 server.js
[root@VM-0-9-centos data]# ./hello.sh
hello world

变量

[root@VM-0-9-centos data]# vi var.sh
[root@VM-0-9-centos data]# ll
总用量 20
drwxr-xr-x 2 root root 4096 12月 30 14:18 C_language
-rw-r--r-- 1 root root   29 12月 30 14:38 hello.js
-rwxr-xr-x 1 root root   19 12月 30 15:30 hello.sh
-rw-r--r-- 1 root root  410 12月 30 14:42 server.js
-rw-r--r-- 1 root root   33 12月 30 15:37 var.sh
[root@VM-0-9-centos data]# chmod +x ./var.sh 
[root@VM-0-9-centos data]# ./var.sh 
Hello World!!!
[root@VM-0-9-centos data]# cat var.sh 
var="Hello World!!!"
echo ${var}
[root@VM-0-9-centos data]# 

数组

[root@VM-0-9-centos data]# ./arr.sh 
hello
world
shell
---------
hello world shell
3
5
[root@VM-0-9-centos data]# cat arr.sh 
# 定义数组,以空格间隔
arr=("hello" "world" "shell")
echo ${arr[0]}
echo ${arr[1]}
# 获取数组某个特定元素
echo ${arr[2]}
echo "---------"
# 获取数组全部元素
echo ${arr[@]}
# 获取数组长度
echo ${#arr[@]}
# 获取数组单个元素长度
echo ${#arr[0]}
目录
打赏
0
0
0
0
24
分享
相关文章
Shell学习(一):Hello World
Java程序员为什么要学习Shell呢? 1)需要看懂运维人员编写的Shell程序。 2)偶尔会编写一些简单Shell程序来管理集群、提高开发效率。
193 0
Shell学习(一):Hello World
定期备份数据库:基于 Shell 脚本的自动化方案
本篇文章分享一个简单的 Shell 脚本,用于定期备份 MySQL 数据库,并自动将备份传输到远程服务器,帮助防止数据丢失。
|
1月前
|
【linux】Shell脚本中basename和dirname的详细用法教程
本文详细介绍了Linux Shell脚本中 `basename`和 `dirname`命令的用法,包括去除路径信息、去除后缀、批量处理文件名和路径等。同时,通过文件备份和日志文件分离的实践应用,展示了这两个命令在实际脚本中的应用场景。希望本文能帮助您更好地理解和应用 `basename`和 `dirname`命令,提高Shell脚本编写的效率和灵活性。
109 32
|
24天前
|
多种脚本批量下载 Docker 镜像:Shell、PowerShell、Node.js 和 C#
本项目提供多种脚本(Shell、PowerShell、Node.js 和 C#)用于批量下载 Docker 镜像。配置文件 `docker-images.txt` 列出需要下载的镜像及其标签。各脚本首先检查 Docker 是否安装,接着读取配置文件并逐行处理,跳过空行和注释行,提取镜像名称和标签,调用 `docker pull` 命令下载镜像,并输出下载结果。使用时需创建配置文件并运行相应脚本。C# 版本需安装 .NET 8 runtime。
113 2
|
5月前
|
一个用于添加/删除定时任务的shell脚本
一个用于添加/删除定时任务的shell脚本
165 1
6种方法打造出色的Shell脚本
6种方法打造出色的Shell脚本
131 2
6种方法打造出色的Shell脚本
|
4月前
|
Shell脚本要点和难点以及具体应用和优缺点介绍
Shell脚本在系统管理和自动化任务中扮演着重要角色。尽管存在调试困难、可读性差等问题,但其简洁高效、易于学习和强大的功能使其在许多场景中不可或缺。通过掌握Shell脚本的基本语法、常用命令和函数,并了解其优缺点,开发者可以编写出高效的脚本来完成各种任务,提高工作效率。希望本文能为您在Shell脚本编写和应用中提供有价值的参考和指导。
188 1
ubuntu/debian shell 脚本自动配置 gitea git 仓库
这是一个自动配置 Gitea Git 仓库的 Shell 脚本,支持 Ubuntu 20+ 和 Debian 12+ 系统。脚本会创建必要的目录、下载并安装 Gitea,创建 Gitea 用户和服务,确保 Gitea 在系统启动时自动运行。用户可以选择从官方或小绿叶技术博客下载安装包。
164 2