初识shell脚本

shell脚本学习——初识shell脚本

打开文本编辑器,使用vi,vim都行。首先规范自己写脚本结尾加.sh(虽然不这样也行,linux也能识别)
其名称也需要见名知意。
规范使用脚本文件,新建练习脚本文件夹

[root@localhost shell_scripts]#

英语渣渣被迫开始学习英语了!!!
从前在学校不好好学,现在工作了,生活教你学英语。
Scripts 脚本
编写运维工作者的第一个脚本!!!

[root@localhost shell_scripts]# vim first_shell_scripts
[root@localhost shell_scripts]# sh first_shell_scripts
Hello World!
[root@localhost shell_scripts]#
[root@localhost shell_scripts]# cat first_shell_scripts
#/bin/bash
echo "Hello World!"

执行脚本有这几种方法

A。没有赋予权限时

[root@localhost shell_scripts]# sh first_shell_scripts
Hello World!
[root@localhost shell_scripts]# bash first_shell_scripts
Hello World!
[root@localhost shell_scripts]# source first_shell_scripts
Hello World!

B。赋予权限后(赋权不要轻易给777)

[root@localhost shell_scripts]# chmod 700 first_shell_scripts
[root@localhost shell_scripts]# ./first_shell_scripts
Hello World!

解释脚本信息元素

#! /bin/bash 指此脚本使用/bin/bash来解释执行。
#! 是一个特殊的表示符,其后跟着解释此脚本的shell路径。
bash只是shell的一种,还有很多其它shell脚本解释器。
系统默认的shell

[root@localhost ~]# echo $SHELL
/bin/bash

系统支持的shell

[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/tcsh
/bin/csh

echo命令

用于在终端设备上输出字符串变量提取后的值
echo后面加引号不加引号单引号的区别
不加引号:字符串原样输出,变量会被替换
单引号:引号里面的内容会原封不动的显示出来
双引号:里面的特殊符号会被解析,变量也会被替换

每篇文章都会不断迭代补充,敬请关注。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值