Score:0

How to store long commands in environment variables in Linux?

it flag

I want to simply run the long command below.

docker ps -a --format "table {{.Image}}\t{{.Ports}}"
export view='docker ps -a --format "table {{.Image}}\t{{.Ports}}"'

test

echo $view
docker ps -a --format "table {{.Image}}\t{{.Ports}}"

Env Variable Exec

$view

Result end Error code

But it runs like below.

"docker ps" accepts no argumets.
See 'docker ps --help'

Usage: docker ps [OPTIONS]

List containers

In short, can't save such long code as an environment variable?

and If possible, can I know another way?

FedKad avatar
cn flag
Why don't you use Bash "aliases": https://tldp.org/LDP/abs/html/aliases.html ?
Score:2
in flag

You should save as array and quote correctly. Only then you can be sure that it expands correctly.

cmd=("docker" "ps" "-a" "--format" "table {{.Images}}\t{{.Ports}}")
"${cmd[@]}"
dodo avatar
it flag
Thank you for your prompt answer for the answer to my question :D
dodo avatar
it flag
thank you for your reply. It's resolved. But the above command doesn't work. It would be appreciated if you could correct the typo with the command below.
dodo avatar
it flag
cmd=("docker" "ps" "-a" "--format" "table {{.Image}}\t{{.Ports}}")
dodo avatar
it flag
oh.. sorry I'm wrong . I need to fix it. images -> image
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.