2

So according to the docs a command written over many lines will expand to multiple parameters. This disagrees with the bash behaviour. For example

hello.lua:

local msg = "Hello, world!" 
return msg

fish>

redis-cli EVAL (cat hello.lua) 0

Fails -

Whereas redis-cli EVAL "$(cat hello.lua)" 0 will succeed in bash. My question is how to prevent the (cat hello.lua) substitution from splitting into multiple parameters due to line breaks?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
user3467349
  • 3,043
  • 4
  • 34
  • 61

1 Answers1

3

fish does not have a direct analog to bash's "$(...)". The current best technique in fish is to manipulate $IFS, which are the characters that trigger splitting. You can make it empty:

set -l IFS
redis-cli EVAL (cat hello.lua) 0

This will pass the entire contents of hello.lua as a single argument.

Assuming you don't want your IFS changes to stick around, you can scope the change to a function, or to a block:

begin
  set -l IFS
  redis-cli EVAL (cat hello.lua) 0
end
ridiculous_fish
  • 17,273
  • 1
  • 54
  • 61
  • Thanks for taking the time to respond. Since Fish aims to be a more practical shell at the cost of some standard compliance, is there a chance we might ever see argument splitting/joining with a built-in function or symbol? [These things are very painful](http://stackoverflow.com/q/10520623/3467349) – user3467349 Jul 19 '15 at 14:38
  • Yes, there's an [old proposal](https://github.com/fish-shell/fish-shell/issues/445) of mine, and a separate proposal for a `string` builtin that will support splitting and joining is being [actively worked on](https://github.com/fish-shell/fish-shell/issues/156) too. – ridiculous_fish Jul 20 '15 at 18:14