小编Mar*_*ker的帖子

如何检测输入是来自参数、文件还是终端

在 bash 中,有没有办法知道给定的脚本是否已被调用:

$ myscript.sh myfile
Run Code Online (Sandbox Code Playgroud)

或者:

$ myscript.sh < myfile
Run Code Online (Sandbox Code Playgroud)

在一些脚本中,我总是访问myfilewith的内容$1,但现在我想根据不同的情况更改行为。

编辑:在没有任何重定向的情况下调用时,我还想要第三种情况:

$ myscript.sh
Run Code Online (Sandbox Code Playgroud)

shell io-redirection

8
推荐指数
2
解决办法
3566
查看次数

如何指定 -?GNU getopt 选项

使用 GNUgetopt命令解析命令行参数时,我如何(如果可能)识别-?为另一个选项?有没有办法在操作字符串中转义它?

bash shell-script getopts

8
推荐指数
1
解决办法
3291
查看次数

标签 统计

bash ×1

getopts ×1

io-redirection ×1

shell ×1

shell-script ×1