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]}
相关文章
Shell学习(一):Hello World
Java程序员为什么要学习Shell呢? 1)需要看懂运维人员编写的Shell程序。 2)偶尔会编写一些简单Shell程序来管理集群、提高开发效率。
210 0
Shell学习(一):Hello World
MySQL 备份 Shell 脚本:支持远程同步与阿里云 OSS 备份
一款自动化 MySQL 备份 Shell 脚本,支持本地存储、远程服务器同步(SSH+rsync)、阿里云 OSS 备份,并自动清理过期备份。适用于数据库管理员和开发者,帮助确保数据安全。
|
2月前
|
确定Shell脚本在操作系统中的具体位置方法。
这对于掌握Linux的文件系统组织结构和路径方面的理解很有帮助,是我们日常工作和学习中都可能使用到的知识。以上讲解详细清晰,应用简便,是每一个想要精通操作系统的计算机爱好者必备的实用技能。
62 17
Centos或Linux编写一键式Shell脚本创建用户、组、目录分配权限指导手册
Centos或Linux编写一键式Shell脚本创建用户、组、目录分配权限指导手册
147 3
|
2月前
|
Centos或Linux编写一键式Shell脚本删除用户、组指导手册
Centos或Linux编写一键式Shell脚本删除用户、组指导手册
59 4
|
3月前
|
在Linux、CentOS7中设置shell脚本开机自启动服务
以上就是在CentOS 7中设置shell脚本开机自启动服务的全部步骤。希望这个指南能帮助你更好地管理你的Linux系统。
162 25
|
9月前
|
一个用于添加/删除定时任务的shell脚本
一个用于添加/删除定时任务的shell脚本
237 1
|
5月前
|
【linux】Shell脚本中basename和dirname的详细用法教程
本文详细介绍了Linux Shell脚本中 `basename`和 `dirname`命令的用法,包括去除路径信息、去除后缀、批量处理文件名和路径等。同时,通过文件备份和日志文件分离的实践应用,展示了这两个命令在实际脚本中的应用场景。希望本文能帮助您更好地理解和应用 `basename`和 `dirname`命令,提高Shell脚本编写的效率和灵活性。
367 32
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问