How to escape a single quote in a Linux command

I was faced an issue while adding an alias in Linux (does not matter which Linux / Unix you are running).

It is a very simple alias, it should just show me the load average for the current host. Obviously you can get these values by typing:

I wanted to add an alias which was looking like this:

For the moment this command seems to work, let’s check this out whether our guess is true:

As you can see this command does not work properly. The alias string is finished after the first single quote.

Okay let’s try another guess:

Also does not work…

I got the command after a lot of try-and-error processes. Afterwards I will show you the final result:

Yeah, finally we got it!

Okay I will explain the syntax of this command below:

  • The first single quote will end the first quotation
  • We have to start a second quotation, but with using a double quote (“)
  • The next single quote is our first escaped single quote (‘)
  • We have to end the second quotation, again with using a double quote (“)
  • The last character of this string will start the third quotation
  • After this, the pattern is just reserved with the same logic

If you have any questions, just comment or write me an email.



Leave a Reply

Your email address will not be published. Required fields are marked *