Linux Command Line and Shell Scripting Bible by Richard Blum; Christine Bresnahan
Author:Richard Blum; Christine Bresnahan
Language: eng
Format: mobi, azw3
Tags: Reference:Computers
ISBN: 9781118004425
Publisher: Wiley
Published: 2008-01-02T10:00:00+00:00
trap “echo byebye” EXIT
count=1
while [ $count -le 5 ]
do
echo “Loop #$count”
sleep 3
count=$[ $count + 1 ]
done
$
$ ./test2
Loop #1
Loop #2
Loop #3
Loop #4
Loop #5
byebye
$
When the script gets to the normal exit point, the trap is triggered, and the shell executes the command you specify on the trap command line. The EXIT trap also works if you prematurely exit the script:
$ ./test2
Loop #1
Loop #2
ˆCbyebye
$
When the Ctrl+C key combination is used to send a SIGINT signal, the script exits (because that signal isn't listed in the trap list), but before the script exits, the shell executes the trap command.
Removing a Trap
You can remove a set trap by using a dash as the command and a list of the signals you want to return to normal behavior:
$ cat test3
#!/bin/bash
# removing a set trap
Download
Linux Command Line and Shell Scripting Bible by Richard Blum; Christine Bresnahan.azw3
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7768)
Filmora Efficient Editing by Alexander Zacharias(5805)
The Infinite Retina by Robert Scoble Irena Cronin(5284)
Learn Wireshark - Fundamentals of Wireshark. by Lisa Bock(3987)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3935)
Edit Like a Pro with iMovie by Regit(3438)
Linux Administration Best Practices by Scott Alan Miller(2858)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic & Jasmin Redzepagic(2837)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2522)
Mastering PowerShell Scripting - Fourth Edition by Chris Dent(2409)
Docker on Windows by Stoneman Elton(2319)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2315)
Creative Projects for Rust Programmers by Carlo Milanesi(2262)
Hands-On AWS Penetration Testing with Kali Linux by Karl Gilbert(2110)
Hands-On Linux for Architects by Denis Salamanca(2053)
Programming in C (4th Edition) (Developer's Library) by Stephen G. Kochan(2006)
Computers For Seniors For Dummies by Nancy C. Muir(2003)
The Old New Thing by Raymond Chen(1941)
Linux Kernel Debugging by Kaiwan N Billimoria(1762)
