.sh文件

1.创建sh文件

使用touch 及vim

2 .  .sh文件添加可执行权限

chmod a+x xxx.sh

a+x代表给所有用户添加可执行x权限

用户类型:

          u: 用户 g:属组 o:其他 a:所有 

权限类型:

        x:执行  w:写  r:读

3.首行内容

#!/bin/bash  或者#!/bin/sh

#!用来告诉系统它后面的参数是用来执行该文件的程序

4.执行方法

方法一:路径/xxx.sh

如:./test.sh 或/path/test.sh(注:不能直接test.sh,会报错test.sh: command not found)

方法二:sh xxx.sh

5.变量

使用花括号${变量名}可告诉系统使用变量,避免系统混淆

echo ¥bianliang_name 显示变量

env 列出环境变量

set 列出环境变量及自定义变量

export 使后续其他文件可以引用该变量,再次执行bash时能够使用之前设定的变量

unset 取消变量

alias unalias 设置别名,取消别名

6.命令

1)linux命令  2)管道/重定向/backtick   3)附带[]条件测试的 if ...;then...流程控制

7.用python创建.sh文件

def myscript():
    scripts="#!/system/bin/bash"+"\n"
    scripts+='my_scriptsXXXXXXXXXX'
    return scripts

A=myscript()
print(A)
with open ('./try.sh','w') as f:
    f.write(A)

8.通配符

比如* ? | ; ¥都是属于通配符

9.连续输入多个指令

command1;command2   两个指令都执行

command1 && command2 表示command1执行没问题后command2执行

command1 || command2 表示command1有错误信息时command2才会执行

 

参考文献:https://blog.csdn.net/ljp812184246/article/details/52585650

 

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值