Hi guys, this is how my script looks like so far:
height=$(($(tput lines) -2))
echo 'Owner Group Other Filename'
echo '----- ----- ----- --------'
echo
cd $directory
path=$(pwd)
levels=0
level=$(($(echo $path | tr '/' ' ' | wc -w) +1))
for dir in / $(echo $path | tr '/' ' ' )
do
cd $dir
levels=$((levels +1))
echo "$(ls -ld | cut -c2-10 | sed 's/.\{3\}/& /' | sed 's/.\{7\}/& /' | sed 's/.\{1\}/& /g') $dir"
echo
done
tput cup $((height)) 0
printf "Valid commands: u(p) d(own) q(uit)"
tput cup $((level * 2 + 4)) 25
#----------------------------I am having problem from here below-------------------------------------
oldsettings=$(stty -g)
stty -icanon min 1 time 0 -echo
key='u'
read key
while [ "$key" != "q" ]
do
if [ "$key" = "u" ]
then tput cup "$((level +1))"
elif [ "$key" = "q" ]
then exit 0
fi
done
stty $oldsettings
--------------------------------------------------------------
This is kinda confusing on how this script works. If you don't know how it works, just paste the code and try it.
Okay, what I'm trying to accomplish is that when this script is executed ( usage : scriptname directory-name-in-the-current-directory ) the cursor is supposed to be on the first letter of the current directory's name.
Then when the user presses the "u" key, the cursor will go up, which is the parent directory of the current directory. So it will keep going up till it hits the root directory.
And same with the "d" key. When "d" is pressed, it will go down until it hits the current directory.
And finally, when the user enters the "q" key, the script will quit.
I would appreciate a lot if someone can fix the script.
Please try to response asap.
Thank you.