N
N
Nikolay Baranenko2022-03-21 20:34:28
linux
Nikolay Baranenko, 2022-03-21 20:34:28

How to properly assign a list of values ​​to a variable?

there is a task to clean Artifactory from unnecessary docker images
for this I use

usage: cleaner.py [-h] [--quiet] [-v] [-U [ARTIFACTORY_URL]] [-u [ARTIFACTORY_USER]] [-p [ARTIFACTORY_PASSWORD]] [-S] {docs,docker,pypi} ...

positional arguments:
  {docs,docker,pypi}

optional arguments:
  -h, --help            show this help message and exit
  --quiet               Don't show info messages
  -v, --verbose         Increase logs verbosity
  -U [ARTIFACTORY_URL], --artifactory-url [ARTIFACTORY_URL]
                        Artifactory URL
  -u [ARTIFACTORY_USER], --artifactory-user [ARTIFACTORY_USER]
                        Artifactory user
  -p [ARTIFACTORY_PASSWORD], --artifactory-password [ARTIFACTORY_PASSWORD]
                        Artifactory password
  -S, --artifactory-secure
                        Does Artifactory use SSL or not


everything is fine, but you can’t delete it by mask, only the exact match of DOCKER_TAG

docker run -it --rm $DOCKER_IMAGE \
-u $ARTIFACTORY_USER \
-p $ARTIFACTORY_PASSWORD \
-U $ARTIFACTORY_URL \
docker $REPO remove any --in v1.0.1-cicd.309 --force


I thought to write a script that will pull out all the values ​​in DOCKER_IMAGE_TAGS through the list method
and then process it again with the

export DOCKER_IMAGE_TAGS=$(
docker run -it --rm $DOCKER_IMAGE -u $ARTIFACTORY_USER \
-p $ARTIFACTORY_PASSWORD \
-U $ARTIFACTORY_URL \
docker $ REPO list
)
echo $DOCKER_IMAGE_TAGS

but in this way saves only the last line of output,
how to save not through the file everything completely in DOCKER_IMAGE_TAGS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2022-03-21
@karabanov

Reading Output of a Command Into an Array in Bash

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question