bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash -f Test Operator - Not working as expected


From: Adam Danischewski
Subject: Bash -f Test Operator - Not working as expected
Date: Sat, 29 Apr 2017 19:47:06 -0400

$ ls -al
/mnt/samsung32/.word_list_repo/instruments_song_repo/546725_pinstripe.mp3
lrwxrwxrwx 1 cronkilla cronkilla 74 Apr 29 19:30
/mnt/samsung32/.word_list_repo/instruments_song_repo/546725_pinstripe.mp3
->
/mnt/samsung32/.word_list_repo/master_song_repo/0/4/5/546725_pinstripe.mp3
$ [[ -L
"/mnt/samsung32/.word_list_repo/instruments_song_repo/546725_pinstripe.mp3"
]] && echo hi
hi
$ [[ ! -L
"/mnt/samsung32/.word_list_repo/instruments_song_repo/546725_pinstripe.mp3"
]] && echo hi
$ [[ -f
"/mnt/samsung32/.word_list_repo/instruments_song_repo/546725_pinstripe.mp3"
]] && echo hi
hi

It looks like the test operator "-f" is not functioning as described,
according to the documentation this should only return true on a REGULAR
file, not a symbolic link.

You can repeat the behavior by creating any symbolic link to a file or
directory and then using the test operator on the command line.

cd /tmp
touch test.txt
ln -s test.txt lnk2test
[[ -f lnk2test ]] && echo hi
[[ -L lnk2test ]] && echo hi
[[ ! -L lnk2test ]] && echo hi

The first test above -f should fail yet doesn't, the last negated symbolic
link test may be a workaround for finding a regular file unless you see
something wrong with that.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]