-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!

3
  • 1
    Does this answer your question? How to escape quotes in shell? Commented Feb 19, 2022 at 6: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
    Commented Feb 19, 2022 at 8:28
  • What shell are you currently using? Is it the csh shell?
    – Kusalananda
    Commented Feb 19, 2022 at 8:28

1 Answer 1

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\'
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .