BayerSe
BayerSe

Reputation: 1171

Command substitution in fish

I'm trying to migrate this working command

docker-compose $(find docker-compose* | sed -e "s/^/-f /") up -d --remove-orphans

from bash to fish. The intention of this command is to get this

docker-compose -f docker-compose.backups.yml ... -f docker-compose.wiki.yml up -d --remove-orphans

My naive try

docker-compose (find docker-compose* | sed -e "s/^/-f /") up -d --remove-orphans

is not working, though. The error is:

ERROR: .FileNotFoundError: [Errno 2] No such file or directory: './ docker-compose.backups.yml'

What is the correct translation?

Upvotes: 0

Views: 243

Answers (1)

Kurtis Rader
Kurtis Rader

Reputation: 7459

The difference in behavior is due to the fact fish, sanely, only splits the output of a command capture on line boundaries. Whereas POSIX shells like bash split it on whitespace by default. That is, POSIX shells split the output of $(...) on the value of $IFS which is space, tab, and newline by default.

There are several ways to rewrite that command so it works in fish. The one that requires the smallest change is to change the sed to insert a newline between the -f and the filename:

docker-compose (find docker-compose* | sed -e "s/^/-f\n/") up -d --remove-orphans

Upvotes: 3

Related Questions