我想打印 /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}"试了一下没有成功。
我想将路径和文件名分配给变量:
/path/to/myfile/file.txt
Run Code Online (Sandbox Code Playgroud)
例如
MYFILE=$(pwd)$(basename)
Run Code Online (Sandbox Code Playgroud)
我该怎么做 ?