一本完整的描述Unix Shell 编程的工具书的所有范例

源代码在线查看: kill-byname.sh

软件大小: 1148 K
上传用户: buptbaishikele
关键词: Shell Unix 编程 范例
下载地址: 免注册下载 普通下载 VIP

相关代码

				#!/bin/bash				# kill-byname.sh: Killing processes by name.				# Compare this script with kill-process.sh.								#  For instance,				#+ try "./kill-byname.sh xterm" --				#+ and watch all the xterms on your desktop disappear.								#  Warning:				#  -------				#  This is a fairly dangerous script.				#  Running it carelessly (especially as root)				#+ can cause data loss and other undesirable effects.								E_BADARGS=66								if test -z "$1"  # No command line arg supplied?				then				  echo "Usage: `basename $0` Process(es)_to_kill"				  exit $E_BADARGS				fi												PROCESS_NAME="$1"				ps ax | grep "$PROCESS_NAME" | awk '{print $1}' | xargs -i kill {} 2&>/dev/null				#                                                       ^^      ^^								# -----------------------------------------------------------				# Notes:				# -i is the "replace strings" option to xargs.				# The curly brackets are the placeholder for the replacement.				# 2&>/dev/null suppresses unwanted error messages.				# -----------------------------------------------------------								exit $?							

相关资源