0

I'm trying to pass a variable via command line so the variable value gets assigned in the script. I also need to display help options via command when I run test.sh -h

I'm able to do this by using the $1 variable (./test.sh us-east-1 or ./tesh.sh us-west-1) but it only works with one argurment.

LOWER = us-east-1

HIGHER = us-west-1

username_json=$(aws xxxx xxxx xxxxxxx --query xxxx --output text --region "us-east-1" )


json_token=$(curl -k \
  -H "Content-Type: application/json" \
  -X POST \
  -d \
'{
   "username":"'$username'",
   "password":"'$password'"
}' \
https://us-east1.xxxxxxx | jq '.token')

I need to run script

./test.sh -e LOWER ===> this should run in lower env with value us-east-1

./test.sh -e HIGHER ==> this should run in higher env with value us-east-1

Aserre
  • 4,916
  • 5
  • 33
  • 56
wlg
  • 159
  • 1
  • 10
  • 1
    See this beautiful answer e.g. :https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash/14203146#14203146 . also try to use markdown, explain what you tried, and what goes wrong. re-read your question, e.g. the last two lines seem contradictional and plain wrong. – Mars Z'uh Dec 07 '21 at 04:44
  • 1
    The code sample you added does not have `$1` in it. How are you using positional arguments ? Also, as Mars Z'uh mentioned, using `getopt` or creating your own arg parsing method is the way to go. – Aserre Dec 07 '21 at 06:10
  • 2
    @wlg : If you post code, please paste it literally. The code you posted should produce an error message _LOWER: command not found_. – user1934428 Dec 07 '21 at 07:18
  • The "variable variables" duplicate tells you how to use one variable to point to another one, which is what you need here. – Charles Duffy Dec 08 '21 at 16:13

0 Answers0