前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >shell学习

shell学习

作者头像
平凡的学生族
发布2020-04-16 14:45:44
2490
发布2020-04-16 14:45:44
举报
文章被收录于专栏:后端技术后端技术

shell:-的作用

${str:=expr}

在shell中使用date命令 注意代码中的括号是全角,运行前要改成半角,否则出错。

$((运算内容))可用于执行整数运算,比如$((5*3))用于执行乘法,

((
((

{firstnu}*${secnu}))执行两个变量相乘。

bash xx.shsource xx.sh区别在于变量是否在父进程生效。

test加参数,可用于判断文件的存在,权限,字符串,文件新旧等。

if else

代码语言:javascript
复制
if condition
  then  commands
elif condition
  then  commands
else
  commands
fi

function

Shell脚本中使用function(函数)示例

python调用shell

How to Execute Shell Commands with Python写得好 Python subprocess.Popen 实时输出 stdout

中文输出/usr目录

代码语言:javascript
复制
list_files = subprocess.Popen(["ls", "-l", "/usr"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line_bytes in list_files.stdout.readlines():
    print(line_bytes.decode('utf-8'), end='')

输出

代码语言:javascript
复制
/usr/bin/python3.6 /home/rasak/PycharmProjects/demo/shell.py
总用量 96
drwxr-xr-x   2 root root 49152 4月  15 00:36 bin
drwxr-xr-x   2 root root  4096 2月   4 02:25 games
drwxr-xr-x  35 root root  4096 4月  14 04:51 include
drwxr-xr-x 128 root root  4096 4月  14 04:44 lib
drwxr-xr-x   3 root root  4096 4月  14 01:23 libexec
drwxr-xr-x  11 root root  4096 4月  15 00:10 local
drwxr-xr-x   2 root root 12288 4月  13 18:15 sbin
drwxr-xr-x 263 root root 12288 4月  14 04:51 share
drwxr-xr-x   6 root root  4096 4月  13 18:15 src

Process finished with exit code 0
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • if else
  • function
  • python调用shell
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档