Debian Codegraph @

set-pos.sh

raw symbols SCIP
1 #!/bin/bash
2
3 variable="one two three four five"
4
5 set -- $variable
6 # Sets positional parameters to the contents of "$variable".
7
8 first_param=$1
9 second_param=$2
10 shift; shift # Shift past first two positional params.
11 # shift 2 also works.
12 remaining_params="$*"
13
14 echo
15 echo "first parameter = $first_param" # one
16 echo "second parameter = $second_param" # two
17 echo "remaining parameters = $remaining_params" # three four five
18
19 echo; echo
20
21 # Again.
22 set -- $variable
23 first_param=$1
24 second_param=$2
25 echo "first parameter = $first_param" # one
26 echo "second parameter = $second_param" # two
27
28 # ======================================================
29
30 set --
31 # Unsets positional parameters if no variable specified.
32
33 first_param=$1
34 second_param=$2
35 echo "first parameter = $first_param" # (null value)
36 echo "second parameter = $second_param" # (null value)
37
38 exit 0