0

I'm creating a function that gets an unspecified number of file names in input and returns an array with the size of all the files. I'm using du to check the file size, but I'm not sure on how to assign every file size to a different element of the array. What I've done so far (not working)

for i in size
do
size[i]=$(du -h "$@")
done

1 Answer 1

1

You can try this:

#!/bin/bash

size=($(du -h "$@" | awk '{ print $1 }'))
echo ${size[@]}

Sample call:

./script.sh config README.md

Sample output:

12M 4,0K
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.