Search
 
SCRIPT & CODE EXAMPLE
 

BASIC

bash catch ctrl-c in a script

#!/bin/bash

function finish() {
        echo "bye bye!"
}

trap finish SIGINT

for number in $(seq 10); do
        echo "TODO: Insert work here..."
        # Insert work to do here.
done
Comment

bash catch ctrl-c in a script

#!/bin/bash
# type "finish" to exit

stty -echoctl # hide ^C

# function called by trap
other_commands() {
    tput setaf 1
    printf "
SIGINT caught      "
    tput sgr0
    sleep 1
    printf "
Type a command >>> "
}

trap 'other_commands' SIGINT

input="$@"

while true; do
    printf "
Type a command >>> "
    read input
    [[ $input == finish ]] && break
    bash -c "$input"
done
Comment

PREVIOUS NEXT
Code Example
Basic :: theme leaf concatenate 
Basic :: hello world in basic 
Basic :: basic authentication in REST api Dajngo 
Basic :: dos/cmd equivalent to "head" 
Basic :: split to list vb.net 
Basic :: remove button selection outline visual basic 
Elixir :: elixir debug 
Elixir :: elixir hello world 
Elixir :: elixir fibonacci 
Elixir :: mix install phoenix 
Elixir :: elixir enum chunk_by 
Scala :: scala schemaPayload json 
Scala :: How to make immutable variable in scala 
Scala :: Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0" 
Actionscript :: read pdf web on android 
Excel :: google sheets convert abbreviation of month to number 
Excel :: excel or function 
Perl :: perl read file 
Perl :: How to run a pearl script 
Pascal :: begin in pascal 
Powershell :: how to download git on windows using power shell 
Clojure :: how to make a range clojure 
Cobol :: Cobol reverse a string 
Assembly :: vba check if shape name exists 
Assembly :: enter 64 bit mode 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: filesaver.min.js cdn 
Javascript :: ajax cdn 
Javascript :: How to get the browser to navigate to a URL in JavaScript 
Javascript :: how to find number in string js 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =