I have exactly these lines in my quite complex script:

echo $SHELL
echo $(which cat)
echo $(alias cat 2>/dev/null) || :

cat <<AAA

echo 1

And it shows an error in debug log:

++++ echo /bin/bash
++++ echo '4.3.46(1)-release'
+++++ which cat
++++ echo /bin/cat
+++++ alias cat
++++ echo
++++ cat
cat: -: No such file or directory

And when I try to repeat the same in simple script - cat works as intended and just prints "test"

(The same happens when I replace AAA with some other word. This is simple docker container from basic "ubuntu" image with some programs installed. And I am pretty sure this exact setup did work fine for some months. Maybe container just broken, but I am still interested to find root cause).

Any idea what can cause the error?

Update next day : TLDR: I believe it was some problem with docker. To address valid comments:

  1. usual $(cat myfile) command did work as expected from the complex script
  2. I am pretty sure that no hidden characters could cause the problem
  3. the script was complex just in amount of things it tries to do; really no hacking like dealing IFS/file-descriptors.
  4. /tmp was ok wtr space and permissions
  5. Now i remember that at some point /dev/shm was 100% filled and despite I cleaned it out - maybe that is related (corrupted something in kernel?)

Today I've booted into that container and it looks broken even more - at least all mounts look corrupted as below :

# ll
ls: cannot access '_template': No such file or directory
drwxr-xr-x  2 root root 4096 Apr  2 13:41 _system/
d?????????  ? ?    ?       ?            ? _template/

So I cannot run script anymore there. I will create new container and expect that it will work properly.

I believe further troubleshooting requires digging into kernel / docker logs and probably not that interesting.

closed as off-topic by Jeff Schaller, GAD3R, Tim Kennedy, dhag, G-Man Apr 5 '17 at 4:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, GAD3R, dhag, G-Man
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    The snippet you posted above looks legit and works. My guess is that something inside cat <<AAA and AAA might break cat. Some unescaped char or whatever. – ddnomad Apr 2 '17 at 22:14
  • You have got a writeable temporary directory accessible from within your docker container? (ls -ld /tmp) – roaima Apr 2 '17 at 22:44
  • 1
    Just to make sure, what's the output of type cat? (which doesn't report functions — you should use type unless you're using csh or zsh) – Gilles Apr 3 '17 at 0:15
  • 2
    You need to show us your complex script coz in there some fiddling with env/IFS/file-descriptors/etc. might be going on which are affecting this. BTW, does "cat somefile" work inside this complex script if you try to add this line in there. That way we can separate the source of error. – user218374 Apr 3 '17 at 0:27
  • 1
    @Rakesh no, that’s just echo $(alias cat 2>/dev/null): +++++ alias cat is the sub-shell, ++++ echo is the echo, not the output of alias cat. – Stephen Kitt Apr 3 '17 at 12:34

Browse other questions tagged or ask your own question.