Re: My script almost works but spams the terminal its launched from if useing dash.
Hi,
Gene Heskett wrote:
> they do not have enough voltage
> across the oxide film to keep it "formed" so the oxide slowly reverts as
> its in an oxygen free environment
I always preferred math over chemistry.
> So I should change my single quotes to double-quotes.
Rather not. At least not as general advise. Beware.
The single '-quotes enclose constants (with special meaning of $'...',
in bash but not in dash).
Their use case is to keep whitespace or special characters from being
converted.
'gene' does not really need them, because it is only one word.
But 'Gene Heskett' or ';(|[$' would need them to be handled as a single
argument to some program run or to avoid shell parser complaints.
$ echo ;(|[$
bash: syntax error near unexpected token `|'
$ echo ';(|[$'
;(|[$
In bash only:
$ echo $'xyz\010abc'
xyabc
(octal 010 = decimal 8 = ASCII BS backspace did eat the "z")
The double "-quotes should often be put around variable evaluations in
order to make the variable content a single argument to some program
run. These quotation marks protect whitespace and some special
characters. But they do not prevent variable evaluation and similar
text conversions.
man bash says:
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, \, and,
when history expansion is enabled, !. The characters $ and ` retain
their special meaning within double quotes. The backslash retains its
special meaning only when followed by one of the following characters:
$, `, ", \, or <newline>. A double quote may be quoted within double
quotes by preceding it with a backslash. If enabled, history expansion
will be performed unless an ! appearing in double quotes is escaped
using a backslash. The backslash preceding the ! is not removed.
One may put each variable into its own "-pair or one may mix constant
text and variable evaluation inside a one pair of "-quotes.
I use the for-loop to demonstrate content and number of perceived
program arguments. Any program or sub script will see the words
between "in" and the first ";" as the argument list which is printed
here by the for-loops.
The appended echo commands produce spacer lines for better readbility.
$ for i in a b c ; do echo "$i" ; done ; echo
a
b
c
$ x='X Y Z'
$ for i in a $x c ; do echo "$i" ; done ; echo
a
X
Y
Z
c
$ for i in a "$x" c ; do echo "$i" ; done ; echo
a
X Y Z
c
$ for i in "a $x c" ; do echo "$i" ; done ; echo
a X Y Z b
$ for i in "a${x}c" ; do echo "$i" ; done ; echo
aX Y Zb
Single quotes and double quotes can protect each other from the
shell parser:
$ echo '"'"$x"'"'
"X Y Z"
$ echo "'"'"'"$x"'"'"'"
'"X Y Z"'
(It can become as inflationary as Lisp brackets ...)
Have a nice day :)
Thomas
Reply to: