Sponsored Content
Top Forums Shell Programming and Scripting moving cursor up and other things Post 302262789 by darkhider on Friday 28th of November 2008 09:52:17 PM
Old 11-28-2008
moving cursor up and other things

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.

Last edited by darkhider; 11-29-2008 at 01:48 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the cursor position

Hello, Is there a way to get the current cursor position? I know "tput sc" saves it. Is there a way to find out the value saved? Thanks. (0 Replies)
Discussion started by: bestbuyernc
0 Replies

2. UNIX for Dummies Questions & Answers

Cursor Positioning

Can anyone tell me how to ouput the current cursor coordinate? I have tried using tput sc and tput rc. However I want to know what the coordinate is. Thanks. (1 Reply)
Discussion started by: bestbuyernc
1 Replies

3. Shell Programming and Scripting

scrolling cursor

Hi, I'm writing scripts in perl and shell and want to add the oprion of scrolling cursor on the screen when there is no output to the screen for long time. I saw it in some script but I don't have the source code. Are anyone know how can I perform this ? Thanks (1 Reply)
Discussion started by: Alalush
1 Replies

4. UNIX for Dummies Questions & Answers

Cursor position

Is there a way of finding the current cursor position (line & column) within AIX (4 Replies)
Discussion started by: gefa
4 Replies

5. Shell Programming and Scripting

ksh - moving cursor position

hi all, am trying to modify a ksh script to group server names together depending on the cluster they sit in. currently the script does a find . -name '*.pid' to find all running servers and prints out their pids and names. current output looks something like this : serverA ... (1 Reply)
Discussion started by: cesarNZ
1 Replies

6. UNIX for Dummies Questions & Answers

Problem to map VIM cursor moving in InsertMode

Hi all What I want? I want in Insert mode, press Alt-hjkl move cursor, and then back to insert mode. I know ctrl-o, hjkl can do the job. but everytime I want to move, i have to press ctrl-o, or I have to count how many hjkl I will do, do a C-O (n)hjkl. What I tried (example only with 'j')... (2 Replies)
Discussion started by: sk1418
2 Replies

7. Shell Programming and Scripting

Using Cursor in Unix - How to do it (Need Help)

Hi, I have a table in which i have the following data JOB_NO FILE_ID FILE_NAME 1546148 1378788 PDF Sample -1.pdf 1546148 1378789 PDF Sample -2.pdf 1546149 1378790 PDF Sample -3.pdf Now I would like use a cursor like thing in unix to download the files using the file ids and send... (1 Reply)
Discussion started by: uuuunnnn
1 Replies

8. Shell Programming and Scripting

Getting the cursor position

I need to get the cursor position, and put it inside a variable. Problem is, i don't have the tput command, or ncurses. Apparently I was supposed to try the following: echo -e '\E But I don't get a value or anything. Please help. (3 Replies)
Discussion started by: tinman47
3 Replies

9. UNIX and Linux Applications

Passing the value of a cursor to another cursor

i have 2 cursors. i want to assign the value of first cursor(employee_id) to the where condition of cursor c2(please refer the bold statement). how do i do if i want to assign the value of c1 to where condition of cursor c2? declare cursor c1 IS select employee_id from employee cursor c2... (1 Reply)
Discussion started by: vkca
1 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 04:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy