heredoc

Javascript heredoc

家住魔仙堡 提交于 2019-11-27 11:37:28
I need something like heredoc in JavaScript. Do you have any ideas for this? I need cross-browser functionality. I found this: heredoc = '\ <div>\ <ul>\ <li><a href="#zzz">zzz</a></li>\ </ul>\ </div>'; I think it will work for me. :) No, unfortunately JavaScript does not support anything like heredoc. mko Try ES6 String Template , you can do something like var hereDoc = ` This is a Multiple Line String `.trim() hereDoc == 'This\nis\na\nMultiple\nLine\nString' => true You can use this great feature today by with 6to5 or TypeScript Zv_oDD How about this: function MyHereDoc(){ /*HERE <div> <p>

Multiline syntax for piping a heredoc; is this portable?

别说谁变了你拦得住时间么 提交于 2019-11-27 09:36:09
问题 I'm familiar with this syntax: cmd1 << EOF | cmd2 text EOF but just discovered that bash allows me to write: cmd1 << EOF | text EOF cmd2 (the heredoc is used as input to cmd1, and the output of cmd1 is piped to cmd2). This seems like a very odd syntax. Is it portable? 回答1: Yes, the POSIX standard allows this. According to the 2008 version: The here-document shall be treated as a single word that begins after the next <newline> and continues until there is a line containing only the delimiter

Passing a variable to a remote host in a bash script with ssh and EOF [duplicate]

半世苍凉 提交于 2019-11-27 09:20:58
This question already has an answer here: Passing external shell script variable via ssh 2 answers I have a script parsing a list of servers, looking for some stuff and executing commands if the circumstances are correct. The main server is connecting to them via ssh, executing all commands that are in the EOF statement: #!/bin/bash # parsing servers # defining one local variable $VAR ssh -T -p 1234 root@"server-ip" "$variable" << 'EOF' # doing some stuff... var_result=$(mysql -hhost -uuser '-ppasswort' -Ddatabase -N -e "SELECT something FROM somewhere WHERE value=$VAR;") EOF I know the

set variable in heredoc section

╄→гoц情女王★ 提交于 2019-11-27 07:59:13
问题 I'm a shell script newbie, so I must be doing something stupid, why won't this work: #!/bin/sh myFile=$1 while read line do ssh $USER@$line <<ENDSSH ls -d foo* | wc -l count=`ls -d foo* | wc -l` echo $count ENDSSH done <$myfile Two lines should be printed, and each should have the same value... but they don't. The first print statement [the result of ls -d foo* | wc -l] has the correct value, the second print statement is incorrect, it always prints blank. Do I need to do something special to

Bash: warning: here-document at line delimited by end-of-file (wanted `EOF') [duplicate]

好久不见. 提交于 2019-11-27 06:58:20
问题 This question already has an answer here: here-document gives 'unexpected end of file' error 5 answers The following function in bash comes up with the error mentioned in the title. The error usually appears when the final EOF is not at the beginning of the line. EOF is at the beginning so I can't see what is wrong. Further up in the script (not shown) there are other here-docs and they work. add_testuser() { kadmin -p admin -q addprinc test cat <<EOF > ~/test.ldif dn: cn=test,ou=groups,dc=$

\n in variable in heredoc

血红的双手。 提交于 2019-11-27 03:25:56
问题 Is there any way to for a Bash heredoc to interpret '\n\' in a heredoc? I have an iteratively built string in a loop, something like for i in word1 word2 word3 do TMP_VAR=$i ret="$ret\n$TMP_VAR" done and then I want to use the created string in a heredoc: cat <<EOF > myfile HEADER == $ret == TRAILER EOF however I would like to interpret the "\n" character as newline, so that the output is HEADER == word1 word2 word3 == TRAILER instead of HEADER == \nword1\nword2\nword3 == TRAILER Is it

JavaScript HERE-doc or other large-quoting mechanism?

萝らか妹 提交于 2019-11-27 01:49:35
问题 Is there a convenient way to quote a large block of HTML that has both single and double quotes in JavaScript? Is there anything like a HERE-doc <<EOF , a multi-quote character """ , or custom delimiters q{} ? Any creative or inventive solutions to this problem? 回答1: Some people don't like this, so be prepared for scorn and derision, but one trick is to dump your "big block of stuff" into a <script language="text"> block: <script id='blockOfStuff' language="text"> Hi this is random stuff <h1

How do I remove leading whitespace chars from Ruby HEREDOC?

两盒软妹~` 提交于 2019-11-27 00:16:17
I'm having a problem with a Ruby heredoc i'm trying to make. It's returning the leading whitespace from each line even though i'm including the - operator, which is supposed to suppress all leading whitespace characters. my method looks like this: def distinct_count <<-EOF \tSELECT \t CAST('#{name}' AS VARCHAR(30)) as COLUMN_NAME \t,COUNT(DISTINCT #{name}) AS DISTINCT_COUNT \tFROM #{table.call} EOF end and my output looks like this: => " \tSELECT\n \t CAST('SRC_ACCT_NUM' AS VARCHAR(30)) as COLUMN_NAME\n \t,COUNT(DISTINCT SRC_ACCT_NUM) AS DISTINCT_COUNT\n \tFROM UD461.MGMT_REPORT_HNB\n" this,

What does <<-CONSTANT do?

老子叫甜甜 提交于 2019-11-26 23:12:02
return <<-HTML <li> <a href = "some-link">Link-Title</a> </li> HTML What are <<-HTML on the first line and HTML on the last line for? cam It's a heredoc. http://en.wikipedia.org/wiki/Here_document#Ruby That's a here document. Basically, it's a multi-line string literal. On lines after the line with the <<-HTML , those are literal strings concatenated by newlines-- until the end marker is reached, which in this case is HTML . To explicitly answer the question, this snippet returns the string: <li> <a href = "some-link">Link-Title</a> </li> 来源: https://stackoverflow.com/questions/4608902/what

Use variable within heredoc in PHP (SQL practice)

一曲冷凌霜 提交于 2019-11-26 22:52:32
问题 I'm a newbie to PHP/SQL and I am trying to use a variable within a heredoc as I need to ut a lot of text. I've only included the first sentence as it is enough to show the problem). My problem is that within the heredoc, the variables (see below: $data['game_name] and $data['game_owner'] ) are not recognized as a variable but as plain text. How can I solve this? <?php try { //i am connecting the the database base mysql 'test' $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $bdd =