Using Indexed Arrays

Learn how to operate on files using an indexed array and clean it afterward.

Copying files using an array

Here is an example of how we can use arrays to operate on files. Let’s suppose the files array contains a list of file names. We want to copy the first file in the list. The following cp call does that:

cp "${files[0]}" ~/Documents

Get hands-on with 1400+ tech skills courses.