-1

I was trying to play around with escape characters in aliases.

Here's a simple example : I want to create an alias for

echo 'Hello'

So I wrote the alias like below :

alias sample 'echo \'Hello\' '

But I see this when I try to source the alias :

Unmatched '.

Any idea why this could be happening?

PS : I know I can use alias "echo 'Hello'" , but I want to test out the escaping in aliases.

Any help is appreciated. Thanks!

  • 1
    Does this answer your question? [How to escape quotes in shell?](https://unix.stackexchange.com/questions/30903/how-to-escape-quotes-in-shell) – αғsнιη Feb 19 '22 at 06:00
  • 1
    @mashuptwice The alias syntax is incorrect for `bash` or any other `sh`-like shell. It is however the correct syntax for `csh` or `tcsh`. The last `alias` command is nonsensical though. The error message is _identical_ to what `csh` (but not `tcsh`) would produce. The `bash` shell would not produce that error. – Kusalananda Feb 19 '22 at 08:28
  • What shell are you currently using? Is it the `csh` shell? – Kusalananda Feb 19 '22 at 08:28

1 Answers1

0

As noted in a comment above, your statement is missing the equals sign. However, consider using a Bash function instead, which are more flexible:

sample() {
    echo \'Hello\'
}

Felicia
  • 19
  • 3