Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Fabian Homborg
@faho
But often it helps to read a line into multiple variables, and handle it line by line.
That single line, and the "..." are there literally?
And what do you need of it?
Alexander Skwar
@alexs77_gitlab
those "..." not, no.
that's secret
Fabian Homborg
@faho
They look like what sort of thing?
Whitespace?
A variable number?
Do you need to preserve any whitespace?
Because I'd be doing something like
Alexander Skwar
@alexs77_gitlab
bash:
set -- $(aws sts assume-role --role-arn "$arn" --role-session-name "switched-role@$(date +%Y-%m-%d--%H.%M.%S.%N)" --output text | sed 1d)
export AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$4" AWS_SESSION_TOKEN="$5"
in the end, I need to store the 2nd "column" in variable AWS_ACCESS_KEY_ID etc.pp.
Fabian Homborg
@faho
aws ... | while read cred asia _ _ _ g4 date 1m _ _ _ nZ
     # handle the fields
end
This gives you the first field in $cred, the second field in $asia, throws away field 3-5, field 6 in $g4, and so on
Alexander Skwar
@alexs77_gitlab
those variables then need to be exported, so that subsequent calls to other programs have AWS_ACCESS_KEY_ID set
Fabian Homborg
@faho
Then export them?
Alexander Skwar
@alexs77_gitlab
=> export AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$4" AWS_SESSION_TOKEN
Fabian Homborg
@faho
Yes?
In that while-loop, do set -gx AWS_ACCESS_KEY_ID $cred; set -gx $AWS_SECRET_ACCESS_KEY $whatever?
Alexander Skwar
@alexs77_gitlab
fish often is quite a bit more complex then bash, isn't it?
Fabian Homborg
@faho
It's a different model
Alexander Skwar
@alexs77_gitlab
yep
Fabian Homborg
@faho
And plenty of things are built with bash assumptions in mind, so the rickety whitespace splitting is assumed
But the thing to do isn't to translate line-by-line, it's to think about what you want to do and translate that.
In this case, you want to extract "fields" from a line and put them into variables.
Which means you want read.
Which doesn't work for bash because of scoping, and also because its read has a number of footguns.
Alexander Skwar
@alexs77_gitlab

thanks, you're right. read might be better.

In bash, I'll probably do now:

read x AWS_ACCESS_KEY_ID x AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN <<< $(aws sts assume-role --role-arn "$arn" --role-session-name "foo" --output text | sed 1d)
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN

And in fish:

aws sts assume-role --role-arn "$arn" --role-session-name "switchedrole" --output text | sed 1d | read -x x AWS_ACCESS_KEY_ID x AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
Alexander Skwar
@alexs77_gitlab
thanks, @faho , this looks better - for both shells.
Fabian Homborg
@faho
Be careful with bash's read.
In particular you most likely want read -r.
Alexander Skwar
@alexs77_gitlab
Thanks, I changed the script to use read -r instead :-)
enzotib
@enzotib
read vars < <(process) is better than read vars <<< $(process)
Alexander Skwar
@alexs77_gitlab
you're right as well
enzotib
@enzotib
someone says me that fish reads .fishrc, is that true?
Fabian Homborg
@faho
@enzotib No.
Fish reads config.fish
fishrc is not, nor has it ever been, a thing.
enzotib
@enzotib
ok, thank you
Fabian Homborg
@faho
The person who told you that probably just assumed fish must be just like the other shells.
There's bashrc and zshrc, so there must be fishrc.
enzotib
@enzotib
he said that he put an export command into it, and he said it worked
Fabian Homborg
@faho
It did not.
Fish does not read fishrc. Either he's fumbled the test or is actively bullshitting you.
You could also just search the code for "fishrc" and see that you come up empty.
Of course it is possible that some third-party thing adds a "fishrc" - that's as simple as adding source ~/.fishrc to one of the files it does read.
But it's not a stock thing, it has never been and it won't be in future.
Because the "rc" convention of naming files is a weird anachronism.
enzotib
@enzotib
I have no problem to believe it