-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_builtin_shift.sh
53 lines (45 loc) · 1.5 KB
/
demo_builtin_shift.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
#!/bin/bash
################################################################################
# Demo of the shift bash built-in"
# The shift built-in shifts script or function input down by 1 or optionally
# more steps.
#
# Sample usage: bash demo_builtin_set.sh arg1 arg2 arg3 arg4 arg5 arg6
#
################################################################################
if [ 4 -ge $# ]
then
echo 'The script expects a four or more inputs.'
echo "Eg: bash demo_builtin_shift.sh arg1 arg2 arg3 arg4 arg5 arg6"
echo "Aborting."
exit 1 # Standard error code. Some others have special meanings.
else
echo 'Four or more arguments given. Continuing script.'
fi
# ------------------------------------------------------------------------------
function printargs {
echo "Number of arguments: $#"
echo "Argument zero: $0"
echo "Arguments given:"
for arg in "$@"
do
echo "Argument: $arg"
done
}
# ------------------------------------------------------------------------------
echo "Demo of the shift bash built-in"
echo "The shift built-in shifts script or function input down by 1 or optionally\
more steps."
# ------------------------------------------------------------------------------
echo "Printing arguments:"
printargs "$@"
# ------------------------------------------------------------------------------
echo "Single shift"
shift
printargs "$@"
# ------------------------------------------------------------------------------
echo "Double shift"
shift 2
printargs "$@"
## End
exit 0 # 0 = success