Linux-Shell-脚本基础使用
Linux-Shell-脚本基础使用
基础使用
-
输出
1
echo "Hello World"
-
变量
1
2
3
4
5
6定义变量 不能有空格
num=100
使用变量(读操作)
echo $num
清除变量
unset num -
获取键盘输入
1
read -p "placeholder..." message
-
创建并执行
shell
1
2
3
4
5
6
7
8!/bin/sh
echo "Hello Shell"
执行
./file-name.sh
. file-name.sh
bash file-name.sh -
环境变量
1
2
3
4
5
6查看环境变量
env
编辑环境变量 搭配使用
vim /stc/profile
使其生效
source /etc/profile -
if
1
2
3
4
5
6
7
8
9!/bin/sh
declare -i 说明 num 为整形
declare -i num=10
if [ $num ]>1; then
num=$num+$num
echo $num
else
echo "error"
fi -
端口查询
1
2
3yum install lsof
查看指定端口有哪些进程在使用
lsof -i:22 -
vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19保存退出
zz
格式化
gg | G
跳转指定行处
nG
显示行号
Esc => :set nu
删除 | 剪切
dd
从光标当前行向下删除指定的行数
ndd
撤销 | 反撤销
u => ctrl + z
ctrl + r => ctrl + y -
查找命令
vim
快捷键 操作 /
/xxx
从光标所在的位置开始搜索, 按 n
向下搜索, N
向上搜索 ?
?xxx
从光标所在位置开始搜索按 n
向上搜索, N
向下搜索 #
将光标移动到待搜索的字符串上, 按 n
向上搜索, N
向下搜索 shift+k
在待搜索的字符串上按 shift+k
,可以查看相关的帮助文档
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 coder-itl!
评论