Bash: Is there a more elegant way to write if statement
My bash script takes 3,5,7,9 or 11 arguments, a file name and a start and stop point to cut from the file, up to five start and stop points, so this is what I've constructed, is there a more elegant way:
Code:
#!/bin/bash No Parameters: Code:
jonke@charlie:~$ HB-Cutter.sh Code:
jonke@charlie:~$ HB-Cutter.sh abc.mp4 12:24 15:30 Code:
jonke@charlie:~$ HB-Cutter.sh abc.mp4 12:24 15:30 18:20 Code:
jonke@charlie:~$ HB-Cutter.sh abc.mp4 12:24 15:30 18:20 20:36 |
There are many ways... getopts is the bash builtin command to parse command line options.
Code:
#!/bin/bash |
Hope this snipped will give you some pointers
Code:
echo file $1 |
Thanks guys, I've used getopts in other scripts, just trying something different, but it's a good suggestion as is the shift method.
I think I might go down the shift method, that'll allow me any number of cuts. Note: I'm a product of the 1970's, cut my teeth on Fortran IV on IBM 360 machines..... "say no more" as they said in Monty Python! |
Quote:
Code:
#!/bin/bash |
If one branch exits then you can leave the other branch empty.
Code:
case ${NARGS} in |
A tricky alternative to the case-esac is
Code:
if [[ " 3 5 7 9 11 " != *" ${NARGS} "* ]] |
All times are GMT -5. The time now is 05:12 PM. |