Skip to content

Commit 6417dae

Browse files
author
Noah Meyerhans
committed
ec2-metadata: fix several shellcheck issues
Shellcheck reported a number of warnings about unquoted references. The specific issues were harmless given the context, but adding quotes helps with consistency. Additionally, shellcheck identified that the '-h' command line option was defined twice (for --local-hostname and --help). Drop one of these references.
1 parent cd3f427 commit 6417dae

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ec2-metadata

+6-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ function set_imds_token()
5858
# param1 = query
5959
function get_meta()
6060
{
61-
local imds_out=$(curl -s -q -H "X-aws-ec2-metadata-token:${IMDS_TOKEN}" -f ${METADATA_BASEURL}/latest/${1})
61+
local imds_out
62+
imds_out=$(curl -s -q -H "X-aws-ec2-metadata-token:${IMDS_TOKEN}" -f ${METADATA_BASEURL}/latest/${1})
6263
echo -n "${imds_out}"
6364
}
6465

@@ -81,7 +82,7 @@ function print_block-device-mapping()
8182
x=$(get_meta meta-data/block-device-mapping/)
8283
if [ -n "${x}" ]; then
8384
for i in $x; do
84-
echo -e '\t' $i: $(get_meta meta-data/block-device-mapping/$i)
85+
echo -e '\t' $i: "$(get_meta meta-data/block-device-mapping/$i)"
8586
done
8687
else
8788
echo not available
@@ -102,7 +103,7 @@ function print_public-keys()
102103
format=$(get_meta meta-data/public-keys/$index/)
103104
echo format:$format
104105
echo 'key:(begins from next line)'
105-
echo $(get_meta meta-data/public-keys/$index/$format)
106+
echo "$(get_meta meta-data/public-keys/$index/$format)"
106107
done
107108
else
108109
echo not available
@@ -116,7 +117,7 @@ function print_tags()
116117
x=$(get_meta meta-data/tags/instance/)
117118
if [ -n "${x}" ]; then
118119
for i in $x; do
119-
echo -e '\t' $i: $(get_meta meta-data/tags/instance/$i)
120+
echo -e '\t' $i: "$(get_meta meta-data/tags/instance/$i)"
120121
done
121122
else
122123
echo not available
@@ -198,7 +199,7 @@ while [ "$1" != "" ]; do
198199
;;
199200
-g | --tags ) print_tags
200201
;;
201-
-h | --help ) print_help
202+
--help ) print_help
202203
exit
203204
;;
204205
--all ) print_all

0 commit comments

Comments
 (0)