file descriptor not generated file descriptor not generated shell shell

file descriptor not generated


This is down to your "if [ -f" statement. It's specifically checking if the FILE (-f) exists. What you've got there in all examples are links, not files. The resolution of those links determine whether the -f query is satisfied or not. When I checked the /var results with an ls on my own system, the link pointed to a character special device, which won't satsify the -f "file exists" criteria.

I'm confused about the direction into the script though. I don't see anywhere that it's actually using the input that you specify. The "var" is entirely self-contained within the script as you have it specified above. To get the -f working on a specified filename, you'd have to do something along the lines of if [ -f $1 ](unless your script changes between the posting and the example runs).


I was able to reproduce the same behavior by removing the file at the beginning of the script:

# cat ./aaa#!/bin/kshrm -f /tmp/file.tmpvar=`ls -lrt /proc/$$/path/0`echo $varif [[  -f /proc/$$/path/0 ]]; then    echo "found file descriptor"else    echo "file descriptor not found"fi

Then:

# touch /tmp/file.tmp# ./aaa < /tmp/file.tmplrwxrwxrwx 1 root root 0 Dec 25 14:52 /proc/784/path/0file descriptor not found

My suggestion is to execute ls -li /var/opt/xxxxxxxx/testip a few times and I'm almost sure you will see different inode with each run, or run it before and after executing the script.

I think that in your case the file is overwritten by something else and you always see the file present but when you launch this script the redirection opens for reading the file from a certain inode, and before the 1st command is executed, the input file is re-written to a different inode which is not know to the script.