Return shell value to a VI macro


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Return shell value to a VI macro
# 1  
Old 07-04-2008
Return shell value to a VI macro

Hi,

Have searched around for a solution to this and get frustrating close but have not nailed it.

vi on HP-UX

what I'm trying to do is utilise the key mapping available within Vi to run a shell script which uses awk script to scan the file i'm working on and return the line number or unique pattern (could go either way but the principle im trying to achieve is pass a value back so that vi macro can then utilise it)

The closest ive got via Google is

The most powerful macros, however, are created using programs combined
into shell scripts (or DOS batch files), and acting as filters on the text
sent to them from within vi. Such shell scripts or programs must take standard
input and send results to standard output (which most UNIX tools do).

but guess what no example! I've tried more in hope than expectation to set a map command as follows:

map ^[[O ^[: !line_test^M

where line_test is hard coded to echo out a line number which then can but as expected all it does is echo out the line number and is not interpreted as the line number I wanted to go to.

I subsequently modified the script to exit with a value and then tried to use $?

map ^[[O :!line_test : ^[: $?^M

but get error badly formatted address

any help greatly appreciated.
# 2  
Old 07-07-2008
found it (sort of)

Despite the absence of any reply (not sure if this question was in the wrong place or just didn't interest anybody!) i have found an answer which i will post as I know from past experience that nothing is more frustrating than trawling the Net for something find it and then found its not been followed up.

I managed to achieve my goal by having the external shell script write out the value to a file in /tmp, the macro then read in the file to the current file , deleted the line and assigned it to buffer 'a' and then using the @ notation to pass to the : (go to line) command.

map ^[[O :!goto_func %^M :r /tmp/goto.mac^M "add:@a^M : !rm -f /tmp/goto.mac^M

still a bit cludgy as edits the existing file, (im thinking is there a way of reading directly into the buffer?) if anyone has a more elegant solution then please post it here.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return Code to shell script

Hi, I need to send the return code from a script to the parent shell script. But i am suppressing outputs while calling the child script. Is there any way still to get the return code from the child script with suppress output. Below is my script: I am using :$ while calling return.sh... (5 Replies)
Discussion started by: usrrenny
5 Replies

2. Shell Programming and Scripting

Return output from shell script

Hi All, There are 2 scripts A and B. A --> It will invoke script B B --> It will generate below output. 100 - connected 105 - Not Connected 210 - Connected I want to return this value to script A. Please advice. (4 Replies)
Discussion started by: Girish19
4 Replies

3. UNIX for Dummies Questions & Answers

opposite return status in c shell

there is something wrong with my system. when I do this: diff file1 file1 && echo 1 the output is 1. but diff file1 file2 >/dev/null && echo 1 output nothing while diff file1 file2 >/dev/null || echo 1 shows 1. the same with "grep" return status. they are both GNU utilities.... (5 Replies)
Discussion started by: phil518
5 Replies

4. Shell Programming and Scripting

Return Value from a FTP shell script

Hello folks,,, I am calling a Unix shell script from java. The unix script is transferring a file through FTP. I wonder how can I confirm whether the script has been executed properly without any error. Is there any way to find the return value from the script. My FTP script is given below ... (3 Replies)
Discussion started by: dinesh1985
3 Replies

5. Shell Programming and Scripting

Return Awk Variable to Shell

I'm a bit stuck in getting variable from awk to shell. I tried searching but most of them showing to assign to shell variable via.. VAR=`echo $line | awk -F: '{print $1}'` which is correct ofcourse My problem is multiple assignments of variable like this one. The above solution will give... (10 Replies)
Discussion started by: ryandegreat25
10 Replies

6. Shell Programming and Scripting

How to return value in shell script

im using bourne shell In file scriptA i add a new function, test_return() test_return() { a=1 return $a } when i try execute , a='/''/scriptA test_return echo $a its give me error.. scriptA: cannot return when not in function ist any solution for this problem.. How... (1 Reply)
Discussion started by: neruppu
1 Replies

7. Programming

Make-question - redefine a macro, using another macro..?

I think there is no problem to use any macro in a new macro definishion, but I have a problem with that. I can not understand why? I have a *.mak file that inludes file with many definitions and rules. ############################################## include dstndflt.mak ... One of the... (2 Replies)
Discussion started by: alex_5161
2 Replies

8. UNIX for Dummies Questions & Answers

Return value from oracle to unix shell

Hi , i have written a shell scipt to call a procedure and get the value back from procedure.But i am facing the issue like #!/bin/sh returnedvalue=`sqlplus -s userid/pass<<EOF set serveroutput on; exec pass($1) set serveroutput off; EXIT; EOF` flag=`echo $returnedvalue ` echo "$flag"... (2 Replies)
Discussion started by: ravi214u
2 Replies

9. Shell Programming and Scripting

How to launch a Csh shell script using Excel Macro ?

Hi all. I need to use excel macro at my desktop to launch a csh script which is in a solaris environment. What is the code that i can use in macro to help me with that ? Basically, the code need to telnet or ftp to the solaris environment and just run the script and the macro will output in an... (1 Reply)
Discussion started by: Raynon
1 Replies

10. UNIX for Dummies Questions & Answers

macro on shell script ?

in shifts we used to run a script where in we need to choose from different options. for example the first part would go like this: ======== menu ======== 1)blah 2)blah blah 3)blah blah blah you have chosen: then after that a series of multiple choice so on and so forth...what i would... (4 Replies)
Discussion started by: inquirer
4 Replies
Login or Register to Ask a Question