博客
关于我
shell知识点:脚本执行方法
阅读量:146 次
发布时间:2019-02-27

本文共 765 字,大约阅读时间需要 2 分钟。

1.shell脚本执行
  • bash script-name 或 sh script-name
    脚本文件本事没有可执行权限(x)或者文件开头没有指定解释器
    sh test.sh  bash test.sh
  • path/script-name 或./script-name
    需要先将脚本文件的权限修改为可执行(chmod u+x script-name 或 chmod 755 script-name)权限
    /server/scripts/test.sh ./test.sh
  • source script-name 或 . script-name
    source 和.执行脚本可以将执行的脚本的函数和变量带到当前执行的shell中
    source test.sh  . test.sh
    第三种执行方法和前两种的区别:
    在这里插入图片描述
    在这里插入图片描述
2.shell脚本后台运行
  • nohup

    nohup sh test.sh > out.txt &

    out.txt为输出日志的地方

  • sh

    sh test.sh >& out.txt &
3.脚本后台执行知识点
功能 用途
sh 脚本 & 将要执行的脚本放到后台执行
ctrl + c 停止执行当前脚本任务
ctrl + z 暂停执行当前脚本任务
bg 将当前脚本任务放到后台执行
fg 将当前脚本任务
  • jobs

    查单当前后台正在运行的任务

    [root@localhost scripts]# jobs[1]-  Running                 sh jobs.sh &[2]+  Running                 sh jobs.sh &
  • fg 序列号

    调出当前正在后台运行的任务到前台执行

    [root@localhost scripts]# fg 1sh jobs.sh
  • nohub

    后台运行程序

转载地址:http://fgvd.baihongyu.com/

你可能感兴趣的文章
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>