Shell wonderful programming example

Source: Internet
Author: User

Reprinted statement: This blog article allow free reprint, but reprint need to indicate the author, source: Denny wqf363@hotmail.com Source: www.huntmine.com Shell-specific variablesTable 14-2 specific s h e l variable $ # number of parameters passed to the script $ * displays all parameters passed to the script using a single string. Different from location variables, this option parameter can contain more than 9 $ ID of the current process in which the script runs $! Process I d of the last process running in the background $ @ is the same as $ #, but it is enclosed by quotation marks, and return each parameter in quotation marks. $-the current option used by s h e l is displayed. The function is the same as that used by s e t. $? Displays the exit status of the last command. 0 indicates no error, and any other value indicates an error. Use the functions in/etc/init. d/funtction to start, State, and stop the process.

Enable numlock automatically upon startup

For T in 'seq 1 8'
Do
Setleds-D + num
$ T>/dev/null
Done

The-D parameter can be used to change the default flags.
Of course, if you change num to caps, scroll can change the status of capslock and scrolllock. Note: Man setleds

In the shell program, 'Press any key'#! /Bin/sh
Get_char ()
{
Savedstty = 'stty-G'
Stty-echo
Stty raw
Dd If =/dev/tty BS = 1 COUNT = 1 2>/dev/null
Stty-raw
Stty echo
Stty $ savedstty
}

Echo "press any key to continue ..."
Char = 'get _ char 'Note: Man sttyHow to kill processes in batchesPS-Ef | grep Java | grep-V grep | awk '{print $2}' | xargs kill-9 start processes in batches

#! /Bin/sh
If [$ #-lt "4"]
Then
Echo usage: Process port username_start username_stop
Fi
Name = $1
I = $3
J = $4
Port = $2
While (I <j ))
Do
$ Name $ port user $ I arg1 arg2 &
(I ++ ))
(Port ++ ))
Done

 

Print directory tree#! /Bin/sh # dtree: Usage: dtree [any directory] dir =$ {1 :-.} (CD $ dir; PWD) find $ Dir-type D-print | sort-f | sed-e "s, ^ $1 ,, "-e"/^ $/D "-e" s, [^/] * // ([^/] */) $,/'----/1, "-e" s, [^/] */, |, G"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.