I have a bash script in which I’m using an array to get a list of files and I needed to pass the content of this array as an argument, to send an email to some users.
This is the array:
RAW_LIST="$(echo "ls -1 /download")"
declare -a LIST
readarray -t LIST <<<"${RAW_LIST}"
This is how I passed the array to bash:
printf %"s\n" "${LIST[@]:1}" | /bin/mail -s "$SUBJECT" "$EMAIL"
Trailing :1
in the array will consider all the elements after element [0]
as, in this specific case, it'd be ls -1
, pretty useless sending it to the user.