Bash case statement

后端 未结 3 1184
傲寒
傲寒 2020-12-31 11:02

I\'m trying to learn case as I was to write a fully functional script.

I\'m starting off with the below

#!/bin/sh
case $@ in

    -h|--help)
                 


        
3条回答
  •  忘掉有多难
    2020-12-31 12:04

    to parse the positional arguments like ... $1 , just use $1 in the case stmt and then at the end ... use shift to pust the 2nd arg to $1 and likewise .

    also i would put the case stmt in a while loop or better a fxn so that i can run it twice for the two options or the number of options ..........

    $# will let you know how many options/arguments were there .

提交回复
热议问题