Bash Script save value without creating temp files

时间:2017-10-12 10:15:33

标签: linux bash shell stdout

i have a bash script with following code :

#!/bin/bash
cat chars.txt | sed 's/.*\(...\)/\1/' > lastchars.txt
aws ses send-email --from Email --destination Email --message file://lastchars.txt
rm lastchars.txt

and my idea is to find a solution to make the same functionality, but without creating Temp file. I've heard and read about STDIN, STDOUT, STDERR, but do not know if this will help me, maybe someone have ideas how to solve this?

2 个答案:

答案 0 :(得分:3)

以简单的方式:

aws ses send-email --from Email --destination Email --message "$(sed 's/.*\(...\)/\1/' chars.txt)"

答案 1 :(得分:2)

如果命令不使用stdin,则可以使用“file”/dev/stdin

cat chars.txt | sed 's/.*\(...\)/\1/' | aws ses send-email --from Email --destination Email --message file:///dev/stdin

否则<()将创建一个管道并返回名称

aws ses send-email --from Email --destination Email --message file://<(cat chars.txt | sed 's/.*\(...\)/\1/')

在文件系统上,这两个选项看起来像这样:

ls -l /dev/stdin <(echo)

lrwxrwxrwx 1 user user 15 Jun 26  2015 /dev/stdin -> /proc/self/fd/0
prw------- 1 user user  0 Oct 12 16:01 /tmp/zshuOs5sV