I'm trying to create a file and assign it to a variable with these lines:
aws_key="company-lab"
source_dir="source_files"
aws_role_list=$(aws iam list-roles --profile="$aws_key" | jq -r '.Roles[].RoleName' > "$source_dir"/aws-"$aws_key"-role-list.txt)
But when I go to use the variable "$aws_role_list" it's empty:
echo "echo the file"
echo "$aws_role_list"
Running the script with bash -x gives you:
+ aws_role_list=
And listing the file like this:
echo "listing the file"
ls -lh "$aws_role_list"
Gives you:
+ ls -lh ''
ls: cannot access '': No such file or directory
What am I doing wrong? How can I use the aws_role_list variable correctly?