Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate string literals

I've seen a couple posts for this, like this one, but none are helping me in my particular situation.

scriptsPath="/var/db/gbi/scripts/"
echo "$scriptsPathawesome.csv";

I would expect this to echo /var/db/gbi/scripts/awesome.csv

Instead I get .csv

Seems like it thinks I'm trying to reference a variable named $scriptsPathawesome. How can I concatenate the $scriptsPath variable to the "awesome.csv" string literal?

like image 358
Nick Rolando Avatar asked Jul 18 '13 16:07

Nick Rolando


People also ask

Can you concatenate string literals?

String literalsThe code concatenates the smaller strings to create the long string literal. The parts are concatenated into a single string at compile time.

How do you add a string literal?

A string literal is a sequence of characters, enclosed in double quotation marks (" ") , which is used to represent a null-terminated string in C/C++. If we try to concatenate two string literals using the + operator, it will fail. For instance, consider the following code, which results in a compilation error: C.

What is an example of a string literal?

A string literal is a sequence of zero or more characters enclosed within single quotation marks. The following are examples of string literals: 'Hello, world!' 'He said, "Take it or leave it."'

Is char * A string literal?

char *amessage = "This is a string literal."; All escape codes listed in the Escape Sequences table are valid in string literals. To represent a double quotation mark in a string literal, use the escape sequence \".


1 Answers

You need to surround your variable with curly braces like so:

scriptsPath="/var/db/gbi/scripts/"
echo "${scriptsPath}awesome.csv";
like image 122
Alfred Fazio Avatar answered Sep 30 '22 10:09

Alfred Fazio