# What are string literals?

Some questions like Significant Whitespace disallowed string literals. But what are string literals exactly? If I interpret this literally, almost everything in Bash or Tcl are string literals. For example, this program in Bash:

echo -n "Hello World!"


is the same as:

"echo" "-n" "Hello World!"


Similarly in Tcl:

puts -nonewline "Hello World!"


is the same as

"puts" "-nonewline" "Hello World!"


echo -n puts -nonewline (and "Hello World!") are all string literals. Even if someone uses only variables like $a in Tcl, arguably it is still something like "$a" in PHP, which is a string literal.

But it seemed those answers are acceptable by the community. In that case what are disallowed in a Bash or Tcl answer exactly?

Some examples:

1. Commands, options, variable names, and anything else that isn't used as strings by the command.
2. printf or date formats, which are options but sometimes also considered strings.
3. Bash aliases, such as alias a="do something", or trap commands, etc.
4. Tcl control structures, such as if 1 "do something".
5. String concatenations, such as "$a$b", c=$a$b in Bash, or "$a$b", $a$b in Tcl.
6. Concatenations that are arguably not of strings, such as $a$b in Bash. if $a or $b contains spaces, the result will be not only one string.
7. Empty strings, such as a= in Bash.
8. Unused strings, such as the -c in alias wc=:; wc -c.

### Edit

I tried to write a shorter one after seeing the Bash answer. But it had alias, printf and even a \n. I thought the \n must disqualified it to be a valid answer. But then I found it hard to tell what answers are acceptable. I also remembered another question with a rule about string literals (but I didn't find it). So I was asking here.

The problem I was thinking was, the rule about string literals are usually just for preventing some trivial solutions. If we require the OP define it accurately like what I have listed per question, it will probably become too complex.

But now it turns out to be just "strings with quote", and I think there probably won't be a general rule like this because it may be very unfair in some challenges. Asking the OP should be the right way.

• You should totally try and drop TCL. – John Dvorak Dec 20 '14 at 10:06

If the OP expected full compliance, then yes, languages like bash would likely be wholly disqualified. Rather, I think the OP usually means “do not use any ‘dead string’ which will directly contribute to the answer.” That is, a format specifier for date or printf is fine if it is just a format specifier (something to format output, not something that contains any of the substantive content to be printed); but if it contains any parts of the requested solution in plain-text, that would be a violation.