Thursday, January 5, 2012

BASH script quotations review.







I often write Bourne Scripts using variables of file locations. Here are several examples of text inputs with results for reference:

#!/bin/sh
folder1="~/Desktop/scriptexp/subfolder 1"
echo $folder1
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo "$folder1"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo '$folder1'
#RESULT>$folder1<
#########################################
folder2='~/Desktop/scriptexp/subfolder 1'
echo $folder1
#RESULT>~/Desktop/scriptexp/subfolder 1"<
echo "$folder1"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo '$folder1'
#RESULT>$folder1<
#########################################
folder3="~/Desktop/scriptexp"
folder4="subfolder 1"
echo "$folder3/$folder4"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo "$folder3/$folder4"
#RESULT>~/Desktop/scriptexp/subfolder 1<
echo '$folder3/$folder4'
#RESULT>$folder3/$folder4<
#****************************************
echo "$folder3/"folder4""
#RESULT>~/Desktop/scriptexp/folder4<
#****************************************
#****************************************
echo "$folder3/'folder4'"
#RESULT>~/Desktop/scriptexp/'folder4'<
#########################################
text1="I like to "go" running."
echo $text1
#RESULT>I like to go running.<
echo "$text1"
#RESULT>I like to go running.<
echo '$text1'
#RESULT>$text1<
text2="I like to 'go' running."
echo $text2
#RESULT>I like to 'go' running.<
echo "$text2"
#########################################
text3='I like to "go" running.'
echo $text3
echo "here"
#RESULT>I like to "go" running.<
echo "$text3"
#RESULT>I like to "go" running.<
echo '$text3'

No comments:

Post a Comment