28 lines
704 B
Markdown
28 lines
704 B
Markdown
# Arguments.
|
|
|
|
## Break flags.
|
|
|
|
If you insert \-\- then all input after that will be treated as non-flags.
|
|
```bash
|
|
rm -- -r -f # this will remove "-r" and "-f" files instead of recursive and force.
|
|
```
|
|
|
|
## Loop over arguments.
|
|
|
|
Handy if you want to loop over files both from arguments or filesystem that include spaces and other special chars. Basically we convert them all to an array and work with it.
|
|
|
|
```bash
|
|
local targets=("${@}") # get array of arguments.
|
|
|
|
# if arguments are empty.
|
|
if [[ "${targets}" = "" ]]; then
|
|
targets=(*.tar) # select all .tar files by default.
|
|
count=${#targets[@]} # calculate the array size.
|
|
fi
|
|
|
|
# iterate.
|
|
for target in "${targets[@]}"; do
|
|
# something.
|
|
done
|
|
```
|