A
A
Alexey Kalinin2014-12-17 16:26:52
linux
Alexey Kalinin, 2014-12-17 16:26:52

How to implement argument checking in bash?

Hello. How to check passed arguments in a bash script? For example, now I am executing the script like this: ./script.sh arg arg2 arg3 But this is not very good, because you can miss, and data from $2 to $1 will go into work, for example. How would you implement validation of input arguments, for example ./script.sh ip=1.1.1.1 host=domain.ltd etc... ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2014-12-17
@gbg

You need getopts

V
Vlad Zhivotnev, 2014-12-21
@inkvizitor68sl

You need shflags - https://code.google.com/p/shflags/
Usage example - https://debian.pro/files/anlamp/mksite.sh (look in the script header)
Ready package for debian/ubunt - https ://debian.pro/files/anlamp/libshflags_1.0.3-y...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question