I've been making a few replacements for standard utilities using only shell built-ins (don't ask why ). But, now I'm really stuck at this "tty"-replacement; I cannot find a way to avoid "ls" - is it at all possible?
tty
Code: Select all
#!/bin/sh
# Uses "ls"
FILE=/proc/$$/fd/0
### readlink -f
while [ -L $FILE ]
do
A=`ls -l $FILE`
FILE=`echo ${A#* -> }`
done
### /readlink -f
echo $FILE
Of course, I can find out if the file is a link:
Code: Select all
# A=`echo /proc/$$/fd/0`
# [ -L $A ] && echo link
link
#
Is it at all possible, or am I banging my head up the wrong tree?
cheers / MHHP