小编Oma*_*AMI的帖子

回显或打印 /dev/stdin /dev/stdout /dev/stderr

我想打印 /dev/stdin、/dev/stdout 和 /dev/stderr 的值。

这是我的简单脚本:

#!/bin/bash
echo your stdin is : $(</dev/stdin)
echo your stdout is : $(</dev/stdout)
echo your stderr is : $(</dev/stderr)
Run Code Online (Sandbox Code Playgroud)

我使用以下管道:

[root@localhost home]# ls | ./myscript.sh
[root@localhost home]# testerr | ./myscript.sh
Run Code Online (Sandbox Code Playgroud)

只是$(</dev/stdin)似乎工作,我也对其他一些问题的人在使用中发现:"${1-/dev/stdin}"试了一下没有成功。

linux shell shell-script stdin

21
推荐指数
1
解决办法
6万
查看次数

连接 pwd 和基本名称

我想将路径和文件名分配给变量:

/path/to/myfile/file.txt
Run Code Online (Sandbox Code Playgroud)

例如

MYFILE=$(pwd)$(basename)
Run Code Online (Sandbox Code Playgroud)

我该怎么做 ?

linux bash basename pwd

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

linux ×2

basename ×1

bash ×1

pwd ×1

shell ×1

shell-script ×1

stdin ×1