Skip to main content
Move "-o" in grep invocation so that it doesn't look so weird
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

This is one of the reasons why the bash manual says:

For almost every purpose, shell functions are preferred over aliases.

dockerid() {
    docker ps -a \
    | grep -o -E '^[a-z0-9]{12}' -o \
    | awk '{printf "%s ",$0} END {print ""}'
}

Although the alias quoting hell goes away by replacing awk with paste

alias dockerid="docker ps -a | grep -o -E '^[a-z0-9]{12}' -o | paste -d ' ' -s"

This is one of the reasons why the bash manual says:

For almost every purpose, shell functions are preferred over aliases.

dockerid() {
    docker ps -a \
    | grep -E '^[a-z0-9]{12}' -o \
    | awk '{printf "%s ",$0} END {print ""}'
}

Although the alias quoting hell goes away by replacing awk with paste

alias dockerid="docker ps -a | grep -E '^[a-z0-9]{12}' -o | paste -d ' ' -s"

This is one of the reasons why the bash manual says:

For almost every purpose, shell functions are preferred over aliases.

dockerid() {
    docker ps -a \
    | grep -o -E '^[a-z0-9]{12}' \
    | awk '{printf "%s ",$0} END {print ""}'
}

Although the alias quoting hell goes away by replacing awk with paste

alias dockerid="docker ps -a | grep -o -E '^[a-z0-9]{12}' | paste -d ' ' -s"
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

This is one of the reasons why the bash manual says:

For almost every purpose, shell functions are preferred over aliases.

dockerid() {
    docker ps -a \
    | grep -E '^[a-z0-9]{12}' -o \
    | awk '{printf "%s ",$0} END {print ""}'
}

Although the alias quoting hell goes away by replacing awk with paste

alias dockerid="docker ps -a | grep -E '^[a-z0-9]{12}' -o | paste -d ' ' -s"