天天看点

程序员之路:Shell基础

1、shell是什么

(1)shell是一个命令行解析器

(2)shell还是一个功能相当强大的编程语言

主要语法有Bourne和C,C有csh和tcsh

程序员之路:Shell基础

2、echo输出命令

echo [选项] [输出内容]

-e:支持反斜线控制的字符转换

程序员之路:Shell基础

3、输出颜色

# echo -e "\e[1;31m hello world \e[0m"

#30m=黑色

#31m=红色

#32m=绿色

#33m=黄色

#34m=蓝色

#35m=洋红

#36m=青色

#37m=白色

4、第一个脚本

# vi hello.sh

#!/bin/bash

#This is comment

echo -e "\e[1;31m hello world \e[0m"

5、脚本执行

(1)赋予执行权限,直接运行

# chmod 755 hello.sh

# ./hello.sh

(2)通过bash调用执行脚本

# bash hello.sh

继续阅读