⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample-bashrc.html

📁 Shall高级编程
💻 HTML
📖 第 1 页 / 共 2 页
字号:
 299&nbsp;{ find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \;  ; } 300&nbsp;# find pattern in a set of filesand highlight them: 301&nbsp; 302&nbsp;function fstr() 303&nbsp;{ 304&nbsp;    OPTIND=1 305&nbsp;    local case="" 306&nbsp;    local usage="fstr: find string in files. 307&nbsp;Usage: fstr [-i] \"pattern\" [\"filename pattern\"] " 308&nbsp;    while getopts :it opt 309&nbsp;    do 310&nbsp;        case "$opt" in 311&nbsp;        i) case="-i " ;; 312&nbsp;        *) echo "$usage"; return;; 313&nbsp;        esac 314&nbsp;    done 315&nbsp;    shift $(( $OPTIND - 1 )) 316&nbsp;    if [ "$#" -lt 1 ]; then 317&nbsp;        echo "$usage" 318&nbsp;        return; 319&nbsp;    fi 320&nbsp;    local SMSO=$(tput smso) 321&nbsp;    local RMSO=$(tput rmso) 322&nbsp;    find . -type f -name "${2:-*}" -print0 | 323&nbsp;    xargs -0 grep -sn ${case} "$1" 2&#62;&#38;- | \ 324&nbsp;    sed "s/$1/${SMSO}\0${RMSO}/gI" | more 325&nbsp;} 326&nbsp; 327&nbsp;function cuttail() # Cut last n lines in file, 10 by default. 328&nbsp;{ 329&nbsp;    nlines=${2:-10} 330&nbsp;    sed -n -e :a -e "1,${nlines}!{P;N;D;};N;ba" $1 331&nbsp;} 332&nbsp; 333&nbsp;function lowercase()  # move filenames to lowercase 334&nbsp;{ 335&nbsp;    for file ; do 336&nbsp;        filename=${file##*/} 337&nbsp;        case "$filename" in 338&nbsp;        */*) dirname==${file%/*} ;; 339&nbsp;        *) dirname=.;; 340&nbsp;        esac 341&nbsp;        nf=$(echo $filename | tr A-Z a-z) 342&nbsp;        newname="${dirname}/${nf}" 343&nbsp;        if [ "$nf" != "$filename" ]; then 344&nbsp;            mv "$file" "$newname" 345&nbsp;            echo "lowercase: $file --&#62; $newname" 346&nbsp;        else 347&nbsp;            echo "lowercase: $file not changed." 348&nbsp;        fi 349&nbsp;    done 350&nbsp;} 351&nbsp; 352&nbsp;function swap()         # swap 2 filenames around 353&nbsp;{ 354&nbsp;    local TMPFILE=tmp.$$ 355&nbsp;    mv "$1" $TMPFILE 356&nbsp;    mv "$2" "$1" 357&nbsp;    mv $TMPFILE "$2" 358&nbsp;} 359&nbsp; 360&nbsp; 361&nbsp;#----------------------------------- 362&nbsp;# Process/system related functions: 363&nbsp;#----------------------------------- 364&nbsp; 365&nbsp;function my_ps() 366&nbsp;{ ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; } 367&nbsp; 368&nbsp;function pp() 369&nbsp;{ my_ps f | awk '!/awk/ &#38;&#38; $0~var' var=${1:-".*"} ; } 370&nbsp; 371&nbsp;# This function is roughly the same as 'killall' on linux 372&nbsp;# but has no equivalent (that I know of) on Solaris 373&nbsp;function killps()   # kill by process name 374&nbsp;{ 375&nbsp;   local pid pname sig="-TERM"   # default signal 376&nbsp;   if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then 377&nbsp;       echo "Usage: killps [-SIGNAL] pattern" 378&nbsp;       return; 379&nbsp;   fi 380&nbsp;   if [ $# = 2 ]; then sig=$1 ; fi 381&nbsp;   for pid in $(my_ps| awk '!/awk/ &#38;&#38; $0~pat { print $1 }' pat=${!#} ) ; do 382&nbsp;       pname=$(my_ps | awk '$1~var { print $5 }' var=$pid ) 383&nbsp;       if ask "Kill process $pid &#60;$pname&#62; with signal $sig?" 384&nbsp;           then kill $sig $pid 385&nbsp;       fi 386&nbsp;   done 387&nbsp;} 388&nbsp; 389&nbsp;function my_ip() # get IP adresses 390&nbsp;{ 391&nbsp;    MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | \ 392&nbsp;sed -e s/addr://) 393&nbsp;    MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | \ 394&nbsp;sed -e s/P-t-P://) 395&nbsp;} 396&nbsp; 397&nbsp;function ii()   # get current host related info 398&nbsp;{ 399&nbsp;  echo -e "\nYou are logged on ${RED}$HOST" 400&nbsp;  echo -e "\nAdditionnal information:$NC " ; uname -a 401&nbsp;  echo -e "\n${RED}Users logged on:$NC " ; w -h 402&nbsp;  echo -e "\n${RED}Current date :$NC " ; date 403&nbsp;  echo -e "\n${RED}Machine stats :$NC " ; uptime 404&nbsp;  echo -e "\n${RED}Memory stats :$NC " ; free 405&nbsp;  my_ip 2&#62;&#38;- ; 406&nbsp;  echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"} 407&nbsp;  echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"} 408&nbsp;  echo 409&nbsp;} 410&nbsp; 411&nbsp;# Misc utilities: 412&nbsp; 413&nbsp;function repeat()       # repeat n times command 414&nbsp;{ 415&nbsp;    local i max 416&nbsp;    max=$1; shift; 417&nbsp;    for ((i=1; i &#60;= max ; i++)); do  # --&#62; C-like syntax 418&nbsp;        eval "$@"; 419&nbsp;    done 420&nbsp;} 421&nbsp; 422&nbsp;function ask() 423&nbsp;{ 424&nbsp;    echo -n "$@" '[y/n] ' ; read ans 425&nbsp;    case "$ans" in 426&nbsp;        y*|Y*) return 0 ;; 427&nbsp;        *) return 1 ;; 428&nbsp;    esac 429&nbsp;} 430&nbsp; 431&nbsp;#======================================================================= 432&nbsp;# 433&nbsp;# PROGRAMMABLE COMPLETION - ONLY SINCE BASH-2.04 434&nbsp;# Most are taken from the bash 2.05 documentation and from Ian McDonalds 435&nbsp;# 'Bash completion' package 436&nbsp;#  (http://www.caliban.org/bash/index.shtml#completion) 437&nbsp;# You will in fact need bash-2.05a for some features 438&nbsp;# 439&nbsp;#======================================================================= 440&nbsp; 441&nbsp;if [ "${BASH_VERSION%.*}" \&#60; "2.05" ]; then 442&nbsp;   echo "You will need to upgrade to version 2.05 \ 443&nbsp;for programmable completion" 444&nbsp;   return 445&nbsp;fi 446&nbsp; 447&nbsp;shopt -s extglob        # necessary 448&nbsp;set +o nounset          # otherwise some completions will fail 449&nbsp; 450&nbsp;complete -A hostname   rsh rcp telnet rlogin r ftp ping disk 451&nbsp;complete -A export     printenv 452&nbsp;complete -A variable   export local readonly unset 453&nbsp;complete -A enabled    builtin 454&nbsp;complete -A alias      alias unalias 455&nbsp;complete -A function   function 456&nbsp;complete -A user       su mail finger 457&nbsp; 458&nbsp;complete -A helptopic  help     # currently same as builtins 459&nbsp;complete -A shopt      shopt 460&nbsp;complete -A stopped -P '%' bg 461&nbsp;complete -A job -P '%'     fg jobs disown 462&nbsp; 463&nbsp;complete -A directory  mkdir rmdir 464&nbsp;complete -A directory   -o default cd 465&nbsp; 466&nbsp;# Compression 467&nbsp;complete -f -o default -X '*.+(zip|ZIP)'  zip 468&nbsp;complete -f -o default -X '!*.+(zip|ZIP)' unzip 469&nbsp;complete -f -o default -X '*.+(z|Z)'      compress 470&nbsp;complete -f -o default -X '!*.+(z|Z)'     uncompress 471&nbsp;complete -f -o default -X '*.+(gz|GZ)'    gzip 472&nbsp;complete -f -o default -X '!*.+(gz|GZ)'   gunzip 473&nbsp;complete -f -o default -X '*.+(bz2|BZ2)'  bzip2 474&nbsp;complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2 475&nbsp;# Postscript,pdf,dvi..... 476&nbsp;complete -f -o default -X '!*.ps'  gs ghostview ps2pdf ps2ascii 477&nbsp;complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype 478&nbsp;complete -f -o default -X '!*.pdf' acroread pdf2ps 479&nbsp;complete -f -o default -X '!*.+(pdf|ps)' gv 480&nbsp;complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf 481&nbsp;complete -f -o default -X '!*.tex' tex latex slitex 482&nbsp;complete -f -o default -X '!*.lyx' lyx 483&nbsp;complete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps 484&nbsp;# Multimedia 485&nbsp;complete -f -o default -X '!*.+(jp*g|gif|xpm|png|bmp)' xv gimp 486&nbsp;complete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321 487&nbsp;complete -f -o default -X '!*.+(ogg|OGG)' ogg123 488&nbsp; 489&nbsp; 490&nbsp; 491&nbsp;complete -f -o default -X '!*.pl'  perl perl5 492&nbsp; 493&nbsp;# This is a 'universal' completion function - it works when commands have 494&nbsp;# a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a' 495&nbsp; 496&nbsp;_get_longopts ()  497&nbsp;{  498&nbsp;    $1 --help | sed  -e '/--/!d' -e 's/.*--\([^[:space:].,]*\).*/--\1/'| \ 499&nbsp;grep ^"$2" |sort -u ; 500&nbsp;} 501&nbsp; 502&nbsp;_longopts_func () 503&nbsp;{ 504&nbsp;    case "${2:-*}" in 505&nbsp;	-*)	;; 506&nbsp;	*)	return ;; 507&nbsp;    esac 508&nbsp; 509&nbsp;    case "$1" in 510&nbsp;	\~*)	eval cmd="$1" ;; 511&nbsp;	*)	cmd="$1" ;; 512&nbsp;    esac 513&nbsp;    COMPREPLY=( $(_get_longopts ${1} ${2} ) ) 514&nbsp;} 515&nbsp;complete  -o default -F _longopts_func configure bash 516&nbsp;complete  -o default -F _longopts_func wget id info a2ps ls recode 517&nbsp; 518&nbsp; 519&nbsp;_make_targets () 520&nbsp;{ 521&nbsp;    local mdef makef gcmd cur prev i 522&nbsp; 523&nbsp;    COMPREPLY=() 524&nbsp;    cur=${COMP_WORDS[COMP_CWORD]} 525&nbsp;    prev=${COMP_WORDS[COMP_CWORD-1]} 526&nbsp; 527&nbsp;    # if prev argument is -f, return possible filename completions. 528&nbsp;    # we could be a little smarter here and return matches against 529&nbsp;    # `makefile Makefile *.mk', whatever exists 530&nbsp;    case "$prev" in 531&nbsp;        -*f)    COMPREPLY=( $(compgen -f $cur ) ); return 0;; 532&nbsp;    esac 533&nbsp; 534&nbsp;    # if we want an option, return the possible posix options 535&nbsp;    case "$cur" in 536&nbsp;        -)      COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;; 537&nbsp;    esac 538&nbsp; 539&nbsp;    # make reads `makefile' before `Makefile' 540&nbsp;    if [ -f makefile ]; then 541&nbsp;        mdef=makefile 542&nbsp;    elif [ -f Makefile ]; then 543&nbsp;        mdef=Makefile 544&nbsp;    else 545&nbsp;        mdef=*.mk               # local convention 546&nbsp;    fi 547&nbsp; 548&nbsp;    # before we scan for targets, see if a makefile name was specified 549&nbsp;    # with -f 550&nbsp;    for (( i=0; i &#60; ${#COMP_WORDS[@]}; i++ )); do 551&nbsp;        if [[ ${COMP_WORDS[i]} == -*f ]]; then 552&nbsp;            eval makef=${COMP_WORDS[i+1]}      # eval for tilde expansion 553&nbsp;            break 554&nbsp;        fi 555&nbsp;    done 556&nbsp; 557&nbsp;        [ -z "$makef" ] &#38;&#38; makef=$mdef 558&nbsp; 559&nbsp;    # if we have a partial word to complete, restrict completions to 560&nbsp;    # matches of that word 561&nbsp;    if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi 562&nbsp; 563&nbsp;    # if we don't want to use *.mk, we can take out the cat and use 564&nbsp;    # test -f $makef and input redirection 565&nbsp;    COMPREPLY=( $(cat $makef 2&#62;/dev/null | \ 566&nbsp;    awk 'BEGIN {FS=":"} /^[^.#   ][^=]*:/ {print $1}' \ 567&nbsp;    | tr -s ' ' '\012' | sort -u | eval $gcmd ) ) 568&nbsp;} 569&nbsp; 570&nbsp;complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake 571&nbsp; 572&nbsp; 573&nbsp;# cvs(1) completion 574&nbsp;_cvs () 575&nbsp;{ 576&nbsp;    local cur prev 577&nbsp;    COMPREPLY=() 578&nbsp;    cur=${COMP_WORDS[COMP_CWORD]} 579&nbsp;    prev=${COMP_WORDS[COMP_CWORD-1]} 580&nbsp; 581&nbsp;    if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then 582&nbsp;        COMPREPLY=( $( compgen -W 'add admin checkout commit diff \ 583&nbsp;        export history import log rdiff release remove rtag status \ 584&nbsp;        tag update' $cur )) 585&nbsp;    else 586&nbsp;        COMPREPLY=( $( compgen -f $cur )) 587&nbsp;    fi 588&nbsp;    return 0 589&nbsp;} 590&nbsp;complete -F _cvs cvs 591&nbsp; 592&nbsp;_killall () 593&nbsp;{ 594&nbsp;    local cur prev 595&nbsp;    COMPREPLY=() 596&nbsp;    cur=${COMP_WORDS[COMP_CWORD]} 597&nbsp; 598&nbsp;    # get a list of processes (the first sed evaluation 599&nbsp;    # takes care of swapped out processes, the second 600&nbsp;    # takes care of getting the basename of the process) 601&nbsp;    COMPREPLY=( $( /usr/bin/ps -u $USER -o comm  | \ 602&nbsp;        sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \ 603&nbsp;        awk '{if ($0 ~ /^'$cur'/) print $0}' )) 604&nbsp; 605&nbsp;    return 0 606&nbsp;} 607&nbsp; 608&nbsp;complete -F _killall killall killps 609&nbsp; 610&nbsp; 611&nbsp;# A meta-command completion function for commands like sudo(8), which 612&nbsp;# need to first complete on a command, 613&nbsp;# then complete according to that command's own 614&nbsp;# completion definition - currently not quite foolproof 615&nbsp;# (e.g. mount and umount don't work properly), 616&nbsp;# but still quite useful -- 617&nbsp;# By Ian McDonald, modified by me. 618&nbsp; 619&nbsp;_my_command() 620&nbsp;{ 621&nbsp;    local cur func cline cspec 622&nbsp;     623&nbsp;    COMPREPLY=() 624&nbsp;    cur=${COMP_WORDS[COMP_CWORD]} 625&nbsp; 626&nbsp;    if [ $COMP_CWORD = 1 ]; then 627&nbsp;	COMPREPLY=( $( compgen -c $cur ) ) 628&nbsp;    elif complete -p ${COMP_WORDS[1]} &#38;&#62;/dev/null; then 629&nbsp;	cspec=$( complete -p ${COMP_WORDS[1]} ) 630&nbsp;	if [ "${cspec%%-F *}" != "${cspec}" ]; then 631&nbsp;	    # complete -F &#60;function&#62; 632&nbsp;	    # 633&nbsp;	    # COMP_CWORD and COMP_WORDS() are not read-only, 634&nbsp;	    # so we can set them before handing off to regular 635&nbsp;	    # completion routine 636&nbsp;	 637&nbsp;	    # set current token number to 1 less than now 638&nbsp;	    COMP_CWORD=$(( $COMP_CWORD - 1 )) 639&nbsp;	    # get function name 640&nbsp;	    func=${cspec#*-F } 641&nbsp;	    func=${func%% *} 642&nbsp;	    # get current command line minus initial command 643&nbsp;	    cline="${COMP_LINE#$1 }" 644&nbsp;	    # split current command line tokens into array 645&nbsp;		COMP_WORDS=( $cline ) 646&nbsp;	    $func $cline 647&nbsp;	elif [ "${cspec#*-[abcdefgjkvu]}" != "" ]; then 648&nbsp;          # complete -[abcdefgjkvu] 649&nbsp;          #func=$( echo $cspec | sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' ) 650&nbsp;          func=$( echo $cspec | sed -e 's/^complete//' -e 's/[^ ]*$//' ) 651&nbsp;	    COMPREPLY=( $( eval compgen $func $cur ) ) 652&nbsp;	elif [ "${cspec#*-A}" != "$cspec" ]; then 653&nbsp;	    # complete -A &#60;type&#62; 654&nbsp;	    func=${cspec#*-A } 655&nbsp;	func=${func%% *} 656&nbsp;	COMPREPLY=( $( compgen -A $func $cur ) ) 657&nbsp;	fi 658&nbsp;    else 659&nbsp;	COMPREPLY=( $( compgen -f $cur ) ) 660&nbsp;    fi 661&nbsp;} 662&nbsp; 663&nbsp; 664&nbsp;complete -o default -F _my_command nohup exec eval \ 665&nbsp;trace truss strace sotruss gdb 666&nbsp;complete -o default -F _my_command command type which man nice 667&nbsp; 668&nbsp;# Local Variables: 669&nbsp;# mode:shell-script 670&nbsp;# sh-shell:bash 671&nbsp;# End:</PRE></TD></TR></TABLE><HR></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="histcommands.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="dosbatch.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">History Commands</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top">&nbsp;</TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Converting DOS Batch Files to Shell Scripts</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -