Author Topic: Test -f Behaves Oddly After Cd Command  (Read 1765 times)

clofland

  • Full Member
  • ***
  • Posts: 247
    • View Profile
    • http://www.lofland.net/
Test -f Behaves Oddly After Cd Command
« on: October 14, 2005, 10:52:31 am »
Write this script:

cd /bin
if (test -f joe);then echo yes1;fi
if (test -f joe);then echo yes2;fi

and run it. (You can use any dir, it doesn't have to be /bin)

There is NO file called "joe" in my /bin directory, but I always get "yes1" but not "yes2"

Is this some known bash or Linux issue where you always get a false possitive on a test -f after you do a cd command?

This causes some of the built in scripts like /etc/ppp/ppp-off to throw out errors sometimes.
C-760 Last Running pdaXrom 1.1.0beta3
- Sandisk UltraII 1GB SD card - Socket LP CF LAN card - Socket LP CF WLAN card - Socket CF Bluetooth Card Rev H -

pgas

  • Hero Member
  • *****
  • Posts: 1097
    • View Profile
    • http://
Test -f Behaves Oddly After Cd Command
« Reply #1 on: October 14, 2005, 01:30:13 pm »
hmm, interesting.

If I place your script on a partition of the internal flash (/ or /home) , it doesn't work correctly.

If I place the same script on my ext3 formatted or on a nfs mount, it works correctly.

if you drop the parentheses it works correctly everywhere.

I tried with "test" from coreutils instead of the "test" from busybox, with the same results.

somehow jffs2 seems to cause problems, i don't have an explanation
SLC-860 cacko / senao wifi

inode0

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Test -f Behaves Oddly After Cd Command
« Reply #2 on: October 14, 2005, 02:21:40 pm »
Quote
Write this script:

cd /bin
if (test -f joe);then echo yes1;fi
if (test -f joe);then echo yes2;fi

and run it. (You can use any dir, it doesn't have to be /bin)

There is NO file called "joe" in my /bin directory, but I always get "yes1" but not "yes2"

Is this some known bash or Linux issue where you always get a false possitive on a test -f after you do a cd command?
Just tested on my 6k and I don't see this bizarre behavior. Nothing is printed from either if statement as one would expect.

John