目录
创建脚本
cat /etc/shells
cd 桌面
touch helloscript.sh
hello world
#! /bin/bash
echo "Hello World"
$ ls -al #查看权限
$ chmod +x helloscript.sh
$ ls -al #文件已变成可执行文件
$ ./helloscript.sh
redirect to file
#! /bin/bash
echo "Hello World" > file.txt
生成file.txt文件,打开看到hello world
cat > file.txt
$ ./hello.sh
# 输入文字 如 hello this is shell ctrl+d
# 打开file.txt
cat >> file.txt
#在后面添加,不是替换
cat 是一个文本文件查看和连接工具。查看一个文件的内容,用cat比较简单,就是cat 后面直接接文件名,如cat linuxyw.txt
< 输入重定向
> 输出重定向
>> 输出重定向,进行追加,不会覆盖之前内容
<< 标准输入来自命令行的一对分隔号的中间内容
cat << eof
this is a test
for cat eof
eof
在一个文件中写入内容
cat > /etc/docker/daemon.sh <<EOF
{
hello hi how are you
i am fine
thank you
}
EOF
EOF只是个标识,不是固定的
comment
# 单行注释
: '
多行注释
多行注释
多行注释
多行注释
多行注释
多行注释'
conditional statements
常用逻辑运算符
-f 判断文件是否存在 eg: if [ -f filename ];
-d 判断目录是否存在 eg: if [ -d dir ];
-eq 等于,应用于整型比较 equal;
-ne 不等于,应用于整型比较 not equal;
-lt 小于,应用于整型比较 letter;
-gt 大于,应用于整型比较 greater;
-le 小于或等于,应用于整型