sh 杂项bash片段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 杂项bash片段相关的知识,希望对你有一定的参考价值。

# use /etc/tcp to make TCP connections in plain bash

exec 3<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.1\r\nhost: http://www.google.com\r\nConnection: close\r\n\r\n" >&3
cat <&3
#!/bin/sh
# POSIX
# Found at http://mywiki.wooledge.org/BashFAQ/035#Manual_loop

# Reset all variables that might be set
file=
verbose=0 # Variables to be evaluated as shell arithmetic should be initialized to a default or validated beforehand.

while :; do
    case $1 in
        -h|-\?|--help)   # Call a "show_help" function to display a synopsis, then exit.
            show_help
            exit
            ;;
        -f|--file)       # Takes an option argument, ensuring it has been specified.
            if [ -n "$2" ]; then
                file=$2
                shift
            else
                printf 'ERROR: "--file" requires a non-empty option argument.\n' >&2
                exit 1
            fi
            ;;
        --file=?*)
            file=${1#*=} # Delete everything up to "=" and assign the remainder.
            ;;
        --file=)         # Handle the case of an empty --file=
            printf 'ERROR: "--file" requires a non-empty option argument.\n' >&2
            exit 1
            ;;
        -v|--verbose)
            verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
            ;;
        --)              # End of all options.
            shift
            break
            ;;
        -?*)
            printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
            ;;
        *)               # Default case: If no more options then break out of the loop.
            break
    esac

    shift
done

# if --file was provided, open it for writing, else duplicate stdout
if [ -n "$file" ]; then
    exec 3> "$file"
else
    exec 3>&1
fi

# Rest of the program here.
# If there are input files (for example) that follow the options, they
# will remain in the "$@" positional parameters.

以上是关于sh 杂项bash片段的主要内容,如果未能解决你的问题,请参考以下文章

sh bash片段

sh Bash的代码片段

sh Git片段#tags:bash

sh Bash片段

sh bash片段 - 这些片段大多只是我自己的笔记;我找到了一些,有些我已经找到了

sh 流浪杂项