Sample Header Ad - 728x90

How Can I Add Short Arguments to a Shell Script

1 vote
1 answer
166 views
To add options, I have the following in one of my scripts:
parse_opts() {
    while [ $# -gt 0 ]; do
	case "$1" in
	    -h|--help)
		help=1
		shift
		;;
	    -r|--raw)
		raw=1
		shift
		;;
	    -c|--copy)
		copy=1
		shift
		;;
        -s|--sensitive)
        sensitive=1
        shift
        ;;
        -i|--insensitive)
        insensitive=1
        shift
        ;;
        *)
        shift
        ;;
    esac
    done
}
There is only one problem, I cannot use multiple options at the same time. For example, using -r -s works but using -rs does not. How can I programmatically make it work without adding separate entries? The shell I am using is sh.
Asked by Amarakon (373 rep)
Jul 5, 2022, 06:56 AM
Last activity: Jun 6, 2024, 11:49 AM