0

The following arguments are valid for docker command:

docker ps -f"status=exited" --format 'table {{.Names}}'
#output:
# jovial_hellman  
# modest_blackwell

So I have created this script

docker-ps-exited

#!/bin/bash
# show exited docker processes
docker ps -f"status=exited" $@

But when I try to add the rest of the arguments in the console it fails:

docker-ps-exited --format 'table {{.Names}}'
# ERROR OUTPUT:
# "docker ps" accepts no arguments.
# See 'docker ps --help'.
# 
# Usage:  docker ps [OPTIONS]

Why the script fails passing the arguments correctly?
How should I write it in order to be able to accept any arguments I pass at the end?

Marinos An
  • 779
  • 7
  • 11
  • 1
    Any reason for not quoting `$@`? Quoting it would mean creating a list of individually quoted elements. Not quoting it would create a list of words that has been split on whitespaces and had filename globbing applied to them to possibly generate more words. See both [Why does my shell script choke on whitespace or other special characters?](//unix.stackexchange.com/q/131766) and [When is double-quoting necessary?](//unix.stackexchange.com/q/68694) – Kusalananda Dec 19 '19 at 13:02
  • That was the issue! Thanks. I didn't know this quoting rule for `$@`. Thanx! – Marinos An Dec 19 '19 at 13:05

0 Answers0