[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] What could cause a script involving $(< /dev/stdin) run diff
From: |
Peng Yu |
Subject: |
[Help-bash] What could cause a script involving $(< /dev/stdin) run differently? |
Date: |
Sat, 12 Jan 2019 07:00:45 -0600 |
Hi,
See below. I run the same script in two different docker containers.
In the second container, I could get an error depending on how I call
the script.
What is the difference between the two ways of calling the script (via
pipeline and via the heredoc) on the 2nd container? There doesn't seem
to be a difference in /dev/pts/0 on the two containers.
Is it caused by a bug in bash or a bug in docker? Thanks.
$ docker run -it --rm ubuntu
address@hidden:/# cat > main.sh <<'EOF'
> #!/bin/bash
> x=$(< /dev/stdin)
> echo "$x"
> EOF
address@hidden:/# chmod +x main.sh
address@hidden:/# ./main.sh <<EOF
> a
> b
> EOF
a
b
address@hidden:/# readlink -e /dev/stdin
/dev/pts/0
address@hidden:/# stat /dev/pts/0
File: /dev/pts/0
Size: 0 Blocks: 0 IO Block: 1024 character special file
Device: 81h/129d Inode: 3 Links: 1 Device type: 88,0
Access: (0620/crw--w----) Uid: ( 0/ root) Gid: ( 5/ tty)
Access: 2019-01-12 12:53:37.911881000 +0000
Modify: 2019-01-12 12:53:37.911881000 +0000
Change: 2019-01-12 12:52:41.141881000 +0000
Birth: -
$ docker run -it --rm -v /tmp:/tmp ubuntu
cat > main.sh <<'EOF'
> #!/bin/bash
> x=$(< /dev/stdin)
> echo "$x"
> EOF
address@hidden:/# chmod +x main.sh
address@hidden:/# ./main.sh <<EOF
> a
> b
> EOF
./main.sh: line 2: /dev/stdin: No such file or directory
address@hidden:/# seq 3 | ./main.sh
1
2
3
address@hidden:/# readlink -e /dev/stdin
/dev/pts/0
address@hidden:/# stat /dev/pts/0
File: /dev/pts/0
Size: 0 Blocks: 0 IO Block: 1024 character special file
Device: 81h/129d Inode: 3 Links: 1 Device type: 88,0
Access: (0620/crw--w----) Uid: ( 0/ root) Gid: ( 5/ tty)
Access: 2019-01-12 12:54:25.196685000 +0000
Modify: 2019-01-12 12:54:25.196685000 +0000
Change: 2019-01-12 12:54:12.326685000 +0000
Birth: -
--
Regards,
Peng
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-bash] What could cause a script involving $(< /dev/stdin) run differently?,
Peng Yu <=