I've been experimenting with the file
command and I came across something intriguing. When I try to loop all the files of a folder and call the file
command the output for .swap and .swp files exhibit a weird behaviour. All 3-letter file/folder names in the current folder are printed as valid extensions for the swap file.
file --extension .test.swp
outputs .test.swp: ???
but calling it in a loop has a different output. the difference can be seen below. This seems to happen only if
- There is a for loop
file --extension
is used- There is a .swp/.swap file which is not empty
- There are files/folders with exactly three characters.
touch a.txt b c def 123 456
for file in `find . -type f`; do
echo $file "->" `file --extension $file` ;
done
echo "test" > .test.swp
echo "-------------"
for file in `find . -type f`; do
echo $file "->" `file --extension $file` ;
done
This prints the output before and after the swap file is added.
./def -> ./def: ERROR: (null)
./a.txt -> ./a.txt: ERROR: (null)
./456 -> ./456: ERROR: (null)
./123 -> ./123: ERROR: (null)
./c -> ./c: ERROR: (null)
./b -> ./b: ERROR: (null)
-------------
./def -> ./def: ERROR: (null)
./.test.swp -> ./.test.swp: 123 456 def
./a.txt -> ./a.txt: ERROR: (null)
./456 -> ./456: ERROR: (null)
./123 -> ./123: ERROR: (null)
./c -> ./c: ERROR: (null)
./b -> ./b: ERROR: (null)
Can anyone explain this weird behaviour?
EDIT: My Shell is GNU bash, version 3.2.57