来自 bash 脚本的操作系统系统调用 [英] OS system calls from bash script

查看:48
本文介绍了来自 bash 脚本的操作系统系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 shell 脚本调用 os 系统调用,如 open、close 等?我试过谷歌搜索,但它把我带到了使用system()"命令的错误方向.有人可以帮忙吗?

Is it possible to call os system calls like open, close etc from a shell script? I tried googling but it takes me in the wrong direction of using "system()" command. Can some one help on this?

推荐答案

许多系统调用都可以访问,但只能通过本机 shell 机制访问,而不能直接指定确切的参数.例如:

Many syscalls are accessible, but only via the native shell mechanisms, rather than being able to directly specify exact parameters. For instance:

exec 4>outfile

调用:

open("outfile", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
dup2(3, 4)

(3 被下一个可用的描述符替换),和

(with 3 being replaced by the next available descriptor), and

exec 4<&-

调用:

close(4)

某些 shell,例如 bash,允许通过可加载模块添加额外的内置函数(请参阅 enable 内置函数,用于加载此类模块);如果您确实需要上游未提供的功能,您可以通过这种方式实现它.

Some shells, such as bash, allow additional builtins to be added through loadable modules (see the enable builtin, used to load such modules); if you really needed functionality not provided upstream, you could potentially implement it that way.

这篇关于来自 bash 脚本的操作系统系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆