How to add arguments to the array ("$ @") in Bash

My script takes a list of files as arguments. I want to add a new argument to an array $@. For a regular array named there fileswill be an addition to the array files+=(name_here.png). How to make to add to $@?

+4
source share
2 answers

I would call @ hek2mgl answer the best answer for a specific array, but if your goal is to explicitly expand $@ , then go to the following:

set -- "$@" '/path/to/file1' '/path/to/file2'
+5
source

I would copy $@to an array and add to this:

files=( "${@}" )
files+=( name_here.png )

Then use ${files}in the script, not ${@}.

+4
source

Source: https://habr.com/ru/post/1688623/


All Articles