Quote inside strings and interpulation examples

Posted on December 23, 2022 · 2 mins read

Quote inside strings and interpulation examples

quotes in strings using Oracle sql and plsql:

Single quote inside of a quoted string is escaped with second single quote: ‘don’‘t’. But better use Q literals: Q’[don’t]’.

select  'don''t walk away!', q'[don't] stay here' from  dual;

The result:

don't walk away! don't stay here

In bash (and inrepilation)

The full explaination is here The behavior is very similar in Perl and PowerShell

echo "don't walk $HOME"                     # --> don't walk /home/sagiv
echo 'don\'t walk $HOME'                    # --> don't walk $HOME
echo "don\'t walk ${HOME}_2"                # --> don't walk /home/sagiv_2

In Perl (and inrepilation)

print ("don't walk $ENV{HOME}\n");          # --> don't walk /home/sagiv
print (qq[don't walk $ENV{HOME}_2\n]);      # --> don't walk /home/sagiv_2
print ( q[don't walk $ENV{HOME}_2\n]);      # --> don't walk /$ENV{HOME}_2\n <--no new line here
printf("don't walk %s\n",$ENV{HOME});       # --> don't walk /home/sagiv

In PowerShell (and inrepilation)

Write-Output "don't go away!"                    # --> don't go away!
Write-Output '"give me one million dollars..!!"' # --> "give me one million dollars..!!"
Write-Output "don't walk $home"                  # --> don't walk /home/sagiv
Write-Output 'don\'t walk $home'                 # --> don't walk $home