T
T
Taras Serevann2018-09-22 01:11:48
bash
Taras Serevann, 2018-09-22 01:11:48

How to write a bash script to iterate through files in a specific directory?

You need to create a bash script that creates a directory and copies there
files whose names begin with the letter A (if the directory is not set, it searches in the home
directory)
It is not possible to name this function of setting the search directory through arguments, the code for file in $2 does not work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-09-22
@Taras_Serevann

You need to create a bash script that creates a directory and copies there files whose names begin with the letter A

To do this, you do not need to iterate over the file names, for this you need to use globbing (cp A* "$2") or, if there are too many files, find + xargs.
for ... inonly works with strings: tryfor file in `ls $2`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question