K
K
Kenny002020-10-29 13:06:56
linux
Kenny00, 2020-10-29 13:06:56

How to correctly execute a command in one line with several arguments, where one of them is a list?

There is a script/program that needs to be executed with 1 command several times. Don't constantly retype the argument. One of the arguments is essentially a list.

You have to do this 10 times... (and then more...)

appman -f /etc/AlterPro/apps_sys.conf standby unregister --sys-id 3
appman -f /etc/AlterPro/apps_map.conf standby unregister --sys-id 3
appman -f /etc/AlterPro/apps_ctrl.conf standby unregister --sys-id 3
 
. . . 

appman -f /etc/AlterPro/apps_port.conf standby unregister --sys-id 3

When trying to do something like this:
exec appman -f /etc/AlterPro/apps_{sys, map, ctrl, port}.conf standby unregister --sys-id 3

The substitution is performed, but all in one command, but you need to do it separately.
Each instance is separate, as if we are calling the script each time, with a new parameter.

And same thought with sudo service {sys, map, ctr, port} restart , restart the service group.

The list will grow, for example, it can be obtained from a text file. Or ls commands .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2020-10-29
@Kenny00

use xargs

echo -n /etc/AlterPro/apps_{sys,map,ctrl,port}.conf | xargs -d" " -n1 -I NAME appman -f NAME standby unregister --sys-id 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question