Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F15539
get-containers-list
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
dereckson
Dec 27 2015, 19:10
2015-12-27 19:10:14 (UTC+0)
Size
758 B
Referenced Files
None
Subscribers
None
get-containers-list
View Options
#!/usr/bin/env bash
## Read /etc/containers.conf and recover docker’s names into an array.
## get-containers-list [--revert]
file
=
'/etc/containers.conf'
if
[[
! -f
"
$file
"
]]
;
then
echo
"
$file
: does not exists "
exit
1
elif
[[
! -r
"
$file
"
]]
;
then
echo
"
$file
: can not read "
fi
#Get names in an array
# 21:42 <geirha> since bash 4, you can use mapfile instead of that while read loop. mapfile -t array < "$file"
mapfile -t array <
"
$file
"
#Test argument to know in wich order return names
if
[[
$1
==
"--revert"
]]
;
then
for
((
i
=
"
${#
array
[*]
}
"
;
i >
0
;
i--
))
;
do
echo
"
${
array
[i]
}
"
done
elif
[[
-z
"
$1
"
]]
;
then
for
((
i
=
0
;
i <
"
${#
array
[*]
}
"
;
i++
))
;
do
echo
"
${
array
[i]
}
"
done
else
echo
"
$1
is not a valid argument"
fi
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
13724
Default Alt Text
get-containers-list (758 B)
Attached To
Mode
D20: Systemd unit to start and stop Docker containers
Attached
Detach File
Event Timeline
Log In to Comment