Paulo Leitao
asked on
MacOSX: awk using input variable from command line
I have this script which return me a list for selection with the correct information
however, I want to dynamically replace the tesvar by a variable pushed from the command line
I'm trying the following:
> /location/mybash.sh testvar
but is not working, I have tried several combinations but without success.
the idea is to filter the below result into a selection list only when the line matches "DBSnapshotIdentifier": "testvar",
If I use the testvar in the script, I will obtain a choice testvar (the name of the instance) if I try to pass it from the command line, it will not work.
how can I filter the value using an input?
#!/bin/bash
choices=('Cancel Restore')
choices+=('Delete Older Instances')
choices+=($(aws rds describe-db-snapshots --db-instance-identifier rdsinstance | awk -F'"' '/"DBSnapshotIdentifier": "testvar",/ { print $4 }'))
select choice in "${choices[@]}"; do
...
however, I want to dynamically replace the tesvar by a variable pushed from the command line
I'm trying the following:
> /location/mybash.sh testvar
#!/bin/bash
variable=$1
choices=('Cancel Restore')
choices+=('Delete Older Instances')
variable=$1
choices+=($(aws rds describe-db-snapshots --db-instance-identifier rdsinstance | awk -v var="$variable" -F'"' '/"DBSnapshotIdentifier": "var",/ { print $4 }'))
select choice in "${choices[@]}"; do
...
but is not working, I have tried several combinations but without success.
the idea is to filter the below result into a selection list only when the line matches "DBSnapshotIdentifier": "testvar",
{
"DBSnapshots": [
{
"DBSnapshotIdentifier": "testvar",
"DBInstanceIdentifier": "rdsinstance",
"SnapshotCreateTime": "2018-05-23T14:32:50.955Z",
"Engine": "sqlserver-ex",
"Status": "available",
"EngineVersion": "11.00.2100.60.v1",
"SnapshotType": "manual",
"DBSnapshotArn": "arn:aws:rds:xxxxxxxxxxxxxxxxxx:snapshot: testvar",
}
]
}
If I use the testvar in the script, I will obtain a choice testvar (the name of the instance) if I try to pass it from the command line, it will not work.
how can I filter the value using an input?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER