Removing quotes from a string

Fish Shell:
Removing quotes from a string

How to:

Fish has built-in magic for this kind of task. Use the string function without breaking a sweat. Check out these spells:

# Example with single quotes
set quoted "'Hello, World!'"
set unquoted (string trim --chars \"\'\" $quoted)
echo $unquoted # Output: Hello, World!

# Same deal with double quotes
set double_quoted "\"Hello, Universe!\""
set unquoted (string trim --chars \"\'\" $double_quoted)
echo $unquoted # Output: Hello, Universe!

Deep Dive

Back in the command-line stone age, you’d wrestle with sed or awk to strip quotes; a real tangle of backslashes and cryptic flags. Fish’s string function is from a newer era, making code cleaner and more intuitive.

Alternatives in other shells might still rely on these old tools or might use their own built-in methods like bash’s parameter expansion or zsh’s modifiers.

The string function goes beyond trimming quotes. It’s a Swiss Army knife for string operations in Fish. With string, you can slice, dice, split, join, or even regex-match strings right in your terminal.

See Also

Dive deeper into string with the help of the official documentation:

For nostalgia or when scripting with more traditional shells, check out: