LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to pass a single quote inside of a single quote... (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-pass-a-single-quote-inside-of-a-single-quote-861714/)

trist007 02-09-2011 06:43 PM

How to pass a single quote inside of a single quote...
 
Here's a command I have to monitor my 3 computers in my lan.
Code:

watch 'printf "BSD\n" && ssh bsd ps u && printf "\n" && ssh bsd iostat && printf "\n################################################################################################################################################\n\nCentOS\n" && ssh centos ps u && printf "\n" && ssh centos iostat && printf "\n################################################################################################################################################\n\nDarkstar\n" && ps u && printf "\n" && iostat'
But I'd like to clean it up and make it look like this. However, the perl -e 'print "#"x145' has single quotes which ends up closing the first single quote at watch 'printf.
Code:

watch 'printf "BSD\n" && ssh bsd ps u && printf "\n" && ssh bsd iostat && printf "\n" && perl -e 'print "#"x145' && printf "\n\nCentOS\n" && ssh centos ps u && printf "\n" && ssh centos iostat && prin
tf "\n" && perl -e 'print "#"x145' && printf "\n\nDarkstar\n" && ps u && printf "\n" && iostat'

Any way around that?

crts 02-09-2011 07:02 PM

Hi,

if you want to escape a single quote inside single quotes you can do it with the following sequence:
Code:

'\''
You actually close the single quote, escape the single quote and then reopen it. Example:
Code:

echo 'quote'\''s'

trist007 02-09-2011 07:07 PM

Awesome thank you.


All times are GMT -5. The time now is 06:12 AM.