bass
bass copied to clipboard
Quotes disappear from arguments when running script through bass
Hi,
First of all, this is probably not a bug but more of a support request. Sorry if this is the wrong forum!
Quotes from my input arguments disappear when I run my script though bass
, but they remain when I run it through bash
.
I have a script:
# my-script.sh
echo $@
When I run it with bash the quotes are preserved (expected):
> bash my-script.sh '{"a":"b"}'
{"a":"b"}
However, when I run it through bass then the quotes disappear (unexpected):
> bass source my-script.sh '{"a":"b"}'
{a:b}
> bass bash my-script.sh '{"a":"b"}'
{a:b}
Would love to get some guidance here! Again, this is probably not a bug in bass
, but just a lack of understanding on my part.
This seems to be caused by passing the '{"a":"b"}'
argument through multiple different shells, each shell stripping some of the quotes. In my case, the outermost quotes '
are stripped by fish, and the innermost "
are stripped by bash.
I wanted to solve this without forcing the user to write a bunch of \
manually. I managed to create a workaround that works in my case.
Workaround
I'm creating a new fish function myscript
that wraps my-script.sh
:
function myscript
# Need to transform {"a":1} into {\"a\":1} before passing to bass
set quoted_argv (echo "$argv" | sed --expression 's/"/\\\\"/g')
bass source /path/to/my-script.sh "$quoted_argv"
end
This then works correctly:
> myscript '{"a":"b"}'
{"a":"b"}
Thanks for documenting this. Can we close this then?
Yep it can!