-
Notifications
You must be signed in to change notification settings - Fork 8
/
input-args.sh
executable file
·71 lines (58 loc) · 1.58 KB
/
input-args.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
echo "amount of arguments:" $#
echo "values:" $@
echo "first argument" ${1}
echo "last argument" ${!#}
# default value or value from env variable
export env_param_value="some value "
unset env_param_value
[[ -z $env_param_value ]] && my_param="default_value" || my_param=$env_param_value
echo $my_param
# check return value
if [[ 1 -eq "$?" ]]; then echo "error"; else echo "done"; fi
if [[ "$1" == `echo "test"` ]];then echo "working"; fi
if [[ $# -gt 3 ]] || [[ $# -eq 0 ]];then
echo "Either 0 or more than 2 input arguments are expected"
exit 1
fi
if [[ $# != 3 ]]
then
echo " 3 input parameters expected"
fi
# check existence for input parameter #2
# if [ ! -n "$2" ]
if [ -z "$2" ]
then
echo "two input parameters are expected: digit and string "
exit 1
fi
param_1=$1
param_2=$2
echo $param_1
echo $param_2
# check input parameters to be in ranges
if [[ $param_1 -gt 0 && $param_1 -lt 25 ]]
then
echo "first argument is positive 0..25"
elif [ $param_1 -ge 25 ] && [ $param_1 -lt 100 ]
then
echo "first argument is positive and Greater Than 25"
else
echo "negative"
fi
echo "---"
# arifmetic operations
param_1_3=$(( $param_1 + $param_1 + $param_1 ))
echo "summarize: "$param_1_3
echo " multiply: "$(( $param_1 * $param_1 * $param_1 ))
echo " divide: "$(( $param_1 * $param_1 * $param_1 / 2 ))
echo " mod: "$(( $param_1 * $param_1 * $param_1 % 2 ))
echo "---"
# length of the string
param_2_len=`echo $param_2 | awk '{print length($0)}'`
echo "param_2 lenght is: "$param_2_len
counter=13
while [ $counter -ge 0 ]
do
counter=$(( counter-1 ))
printf ".%d" $counter
done