I have this simplified command, executed in a .bashrc function:
aws sso login --profile myprofile --cli-read-timeout 5
I’m trying to replace the command options with an array of options:
params=('--profile myprofile')
params+=('--cli-read-timeout 5')
aws sso login "${params[*]}"
AWS complains about unknown options:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: --profile myprofile --cli-read-timeout 5
What is the correct format to be used in order to properly execute the command?
>Solution :
The option name and its argument must be separate array elements.
params=('--profile' 'myprofile')
params+=('--cli-read-timeout' '5')
aws sso login "${params[@]}"
or you can use --option=value syntax:
params=('--profile=myprofile')
params+=('--cli-read-timeout=5')
aws sso login "${params[@]}"
Also, you must use ${params[@]} rather than ${params[*]} so that each array element will be expanded to a separate word.
Your code is equivalent to combining all the parameters into a single argument:
aws sso login '--profile myprofile --cli-read-timeout 5'