(a) typing more stuff
(b) looking in my notes to remember what I need, in order to type more stuff
Geeking in technology since 1985, with IBM Development, focused upon Docker and Kubernetes on the IBM Z LinuxONE platform In the words of Dr Cathy Ryan, "If you don't write it down, it never happened". To paraphrase one of my clients, "Every day is a school day". I do, I learn, I share. The postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions. Remember, YMMV https://infosec.exchange/@davehay
Following on from my earlier post: -
Wow, why have I not been using 1Password for my SSH keys before today ?
I've got a little further, with various API keys now stored in my 1Password vault
This is far simpler, in that the vault entry, of type API Credential, only needs to have a name/title e.g. IBM Cloud API Key and a credential, the actual API key itself.
With that in place, I've then setup an alias to retrieve/display the API key: -
apikey='export APIKEY=$(op item get "IBM Cloud" --field credential) && echo $APIKEY'
in ~/.zprofile, meaning that I just need to run the "command" apikey to ... see my API key.
I will, of course, be leveraging the same API keys in various other scripts/aliases, including things that login to IBM Cloud etc.
So, technically I learned this yesterday but 🤷♀️
As part of our CI/CD testing, we run shellcheck against our shell scripts, and saw the following: -
^----^ SC2086 (info): Double quote to prevent globbing and word splitting.
for a piece of code that referenced a variable e.g. : -
echo $FILES
The shellcheck Wiki covers this: -
and suggests that $FILES be wrapped in double quotes e.g. : -
echo "$FILES"
So far, so good
However, the code in question was actually a variable containing more than one element e.g. : -
FILES="a.txt b.txt c.txt"
so the next line in the script which leveraged the values within the $FILES variable: -
ls "$FILES"
fails with: -
ls: a.txt b.txt c.txt: No such file or directory
Thinking more about this, this kinda made sense i.e. we're treating the values within the $FILES variable as elements within an array, but we're not actually treating the variable as an array, by incrementing through the elements by an index.
The Wiki does reference this: -
Using that as inspiration, I updated the script: -
In essence, this is creating a "real" array from the $FILES variable, and then we're incrementing the index using [@]
To be clear, I also took inspiration from: -
How to be explicit about intentional word splitting?
and this is my demo / test script: -
which, when I run it, does this: -
./test-sc.sh
Works, but breaks shellcheck
a.txt b.txt c.txt
Fails, but passes shellcheck
ls: a.txt b.txt c.txt: No such file or directory
Works, and passes shellcheck
a.txt b.txt c.txt
Finally, for now, there's a great shellcheck plugin for VS Code: -
ShellCheck for Visual Studio Code
and, for the record, the shellcheck project is available on GitHub
This follows on from: - Lest I forget - how to install pip on Ubuntu I had reason to install podman and skopeo on an Ubuntu box: - lsb_rel...