Vi : Is it possible to send ctrl + d signal from a file made with vi and executing it.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vi : Is it possible to send ctrl + d signal from a file made with vi and executing it.
# 1  
Old 04-03-2013
Vi : Is it possible to send ctrl + d signal from a file made with vi and executing it.

Hi Experts,

Is it possible to send ctrl + d signal from a inside a file made with vi, using Ctrl V , Esc and 004 , escape sequence.

Since : [ CTRL-D EOT (End of transmission) ] 004 should exit the script if executed. Is this something possible.

I am trying with vi , I put this code
Code:
^[004

, and trying to execute it but not working:
Getting error, while executing the file:

Code:
testfile: ^[004:  not found.


to construct this used:
^[004 ## To do this : 1. vi ,then Esc i , then Esc V Esc , then type 004

But not working.

Thanks,
# 2  
Old 04-03-2013
I don't think you can use ^D here. Why don't you use the exit command to exit a script?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 04-03-2013
It does not make sense to put CTL-D inside a script file for purposes of exiting the script. As previously suggested, use "exit".

If you want to enter CTL-D into the file, using vi, just use CTL-V CTL-D sequence.

When a program is receiving input from stdin, you can enter CTL-D at the beginning of a line to signal "end of file". I think that's what you're getting mixed up. "end of file" for a Unix file is just signaled by end of file (no more content), period. Putting CTL-D in the middle of the file does not signal "end of file". You can verify with a test. Put CTL-D somewhere toward the top of the file, and cat the file. The whole file is shown, not just the part before the CTL-D.
This User Gave Thanks to hanson44 For This Post:
# 4  
Old 04-03-2013
Thanks both, ll look for the workaround mentioned .
# 5  
Old 04-03-2013
Can you tell us what exactly you are trying to do?

If you are trying to instruct a script to handle certain task while it is already running, then you can use trap to catch a user-defined signal and perform an action.

For example, here is a script:
Code:
#!/bin/ksh

while :
do
        trap "echo Date: $(date)" USR1
        echo "Sleeping for 5 seconds..."
        sleep 5
done

If you run this script on a session and from another session if you send a USR1 signal to the running script PID, the trap argument will be executed:
Code:
kill -USR1 <PID>

Modify it as per your requirement. I hope this helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect command to send the user input enter or ctrl+c

Hey All, I am writing one script using expect, that script which is used in spawn will accepts only 1. Enter 2. Ctrl+c Press Control-C to exit, Enter to proceed. Could some one share some thoughts to send the above user inputs in linux expect block ? Thanks, Sam (0 Replies)
Discussion started by: SCHITIMA
0 Replies

2. Shell Programming and Scripting

Send ctrl-C signal using bash script.

declare -a array=( "LLC-load-misses" "LLC-loads" "LLC-store-misses" "LLC-stores" "branch-load-misses" "branch-loads" "dTLB-load-misses" "dTLB-loads" "dTLB-store-misses" "dTLB-stores" "iTLB-load-misses" "iTLB-loads" "branch-instructions" "branch-misses" "bus-cycles" "cache-misses" "cache-references"... (2 Replies)
Discussion started by: BHASKAR JUPUDI
2 Replies

3. AIX

Send ctrl+C in expect script

Hi, Am trying to transfer file via FTP using expect script from server to client i need to interrupt the file transfer between server and client Please help what should used in expect code.. I used send "ctrl+c\r" expect "Aborted" but that didnt work.. I need what should... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

4. Shell Programming and Scripting

ctrl c trapping signal

im trying to make a trap signal 2 (ctrl c) in a bash script if a user presses ctrl c while running the script it should display an error message but not quit the bash script just yet. User will have to press "enter" to quit This is what i have so far #trap trap_control 2 #while true #do... (6 Replies)
Discussion started by: gangsta
6 Replies

5. Shell Programming and Scripting

Script to send alert if any changes are made in crontab.

Hi i want to know how can i write a script to check if any changes are made and send an alert in crontabs . i am using .ksh file extension for writing scripts. (3 Replies)
Discussion started by: honey26
3 Replies

6. Programming

how can i make that a process child send a signal?

I'm trying to do a program that makes activate an signal (SINGALARM) when the next child of a son appears but this not works. I have to caught the next child o the other (pid), to send a singnal which inform a menssage. It's anything worng in the code? thanks. the code: #include... (2 Replies)
Discussion started by: marmaster
2 Replies

7. Shell Programming and Scripting

How to send Ctrl Break combination in Expect

Greetings, I am writing an Expect script to automate multiple processes on an HP-UX system. Everything has gone fine so far but I now have run into a problem. One of the processes that I'm trying to automate requires the key combination of ctrl break and I have so far been unable to figure out... (1 Reply)
Discussion started by: g_trueblood2000
1 Replies

8. Shell Programming and Scripting

How to send SIGNAL to the thread?

Hello, I have to send SIGSEGV to the thread. What is the simplest and efficient way to do that? (6 Replies)
Discussion started by: Rahulpict
6 Replies

9. Shell Programming and Scripting

Ctrl-C signal propagation

Hello I have a master startup script (let's call it myScript) that displays a menu from which the user can start/stop several instances of a server. When I issue the start command for one of the servers from the menu and then exit myScript through the provided mechanism (enter "q" in this case),... (2 Replies)
Discussion started by: EvilBoz
2 Replies

10. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies
Login or Register to Ask a Question