heredoc

Why does this shell script work for one instance and not the other? [duplicate]

徘徊边缘 提交于 2021-02-10 13:17:14
问题 This question already has answers here : How to cat <<EOF >> a file containing code? (4 answers) Closed 2 years ago . I'm in need of some explanation of the following code, because they are the same concepts but not working the same. So, I'm trying to do the following: #!/bin/sh ssh -T username@host << EOF relative="$HOME/Documents" command=$(find \$relative -name GitHub) command2=$(echo \$relative) echo "HERE: \$command" echo "HERE: \$command2" EOF Here is the output I get: find: ‘$relative’

Compress heredoc declaration to one line in bash?

允我心安 提交于 2021-02-08 17:11:46
问题 I have this which works to declare a JSON string in a bash script: local my_var="foobar" local json=`cat <<EOF {"quicklock":"${my_var}"} EOF` The above heredoc works, but I can't seem to format it any other way, it literally has to look exactly like that lol. Is there any way to get the command to be on one line, something like this: local json=`cat <<EOF{"quicklock":"${my_var}"}EOF` that would be so much nicer, but doesn't seem to take, obviously simply because that's not how EOF works I

Compress heredoc declaration to one line in bash?

邮差的信 提交于 2021-02-08 17:01:05
问题 I have this which works to declare a JSON string in a bash script: local my_var="foobar" local json=`cat <<EOF {"quicklock":"${my_var}"} EOF` The above heredoc works, but I can't seem to format it any other way, it literally has to look exactly like that lol. Is there any way to get the command to be on one line, something like this: local json=`cat <<EOF{"quicklock":"${my_var}"}EOF` that would be so much nicer, but doesn't seem to take, obviously simply because that's not how EOF works I

Heredoc: what does the commonly used 'EOT' actually mean?

落爺英雄遲暮 提交于 2021-02-06 14:20:53
问题 PHP's Heredoc examples always seem to use EOT (and sometimes EOD) as the seperating string, while it is actually possible to use any string here. This works: $mystring = <<<EOT Foo Bar Baz EOT; While this works as well: $mystring = <<<MONKIES Foo Bar Baz MONKIES; Does EOT actually stand for something and if so, what? 回答1: ​It stands for "End Of Text".​ 回答2: Actually end of text would be ETX – EOT is end of transmission . Reference: ASCII - Wikipedia 回答3: I prefer to go for the TRON reference

Generate script in bash and save it to location requiring sudo

北城以北 提交于 2021-02-05 20:23:51
问题 In bash I can create a script with a here-doc like so as per this site: http://tldp.org/LDP/abs/html/abs-guide.html#GENERATESCRIPT ( cat <<'EOF' #!/bin/bash #? [ ] / \ = + < > : ; " , * | #/ ? < > \ : * | ” #Filename="z:"${$winFn//\//\\} echo "This is a generated shell script." App='eval wine "C:\Program Files\foxit\Foxit Reader.exe" "'$winFn'"' $App EOF ) > $OUTFILE If my $OUTFILE is a directory requiring sudo privileges where do I put the sudo command or what else can I do to make it work?

Generate script in bash and save it to location requiring sudo

人盡茶涼 提交于 2021-02-05 20:17:22
问题 In bash I can create a script with a here-doc like so as per this site: http://tldp.org/LDP/abs/html/abs-guide.html#GENERATESCRIPT ( cat <<'EOF' #!/bin/bash #? [ ] / \ = + < > : ; " , * | #/ ? < > \ : * | ” #Filename="z:"${$winFn//\//\\} echo "This is a generated shell script." App='eval wine "C:\Program Files\foxit\Foxit Reader.exe" "'$winFn'"' $App EOF ) > $OUTFILE If my $OUTFILE is a directory requiring sudo privileges where do I put the sudo command or what else can I do to make it work?

Bash assign output to variable inside here document

我与影子孤独终老i 提交于 2021-02-05 09:46:06
问题 In a bash script, what I need is to ssh to a server and do some commands, what I got so far is like this: outPut="ss" ssh user@$serverAddress << EOF cd /opt/logs outPut="$(ls -l)" echo 'output is ' $outPut EOF echo "${outPut}" But the output from terminal is: output is ss ss The output was assigned to the output from command ls -l , but what it showed is still the original value, which is ss . What's wrong here? 回答1: There are actually two different problems here. First, inside a here

coloring in heredocs, bash

◇◆丶佛笑我妖孽 提交于 2021-02-05 06:21:11
问题 If I have previously defined color variable like this: txtred='\e[1;31m' How would I use it in heredoc : cat << EOM [colorcode here] USAGE: EOM I mean what should I write in place of [colorcode here] to render that USAGE text red? ${txtred} won't work, as that is what I am using throughout my bash script, outside of heredoc 回答1: You need something to interpret the escape sequence which cat won't do. This is why you need echo -e instead of just echo to make it work normally. cat << EOM $(echo

PHP's HERE Doc (EOT) syntax highlighting discrepancy with forward slash on Sublime Text 3

不打扰是莪最后的温柔 提交于 2021-01-28 02:27:08
问题 I am unfamiliar with how Sublime Text 3 uses syntax highlighting, as in, if it purely relies on the theme or has it's built in standard that themes run off of but in my case, there's some syntax highlighting discrepancy with using PHP's HERE docs and forward slashes. Once a forward slash is present, it appears ST3 thinks all the following code is apart of that tag. Is this something I can fix? Forward slash syntax highlighting discrepancy No forward slash and correct syntax highlighting 回答1:

PHP's HERE Doc (EOT) syntax highlighting discrepancy with forward slash on Sublime Text 3

雨燕双飞 提交于 2021-01-27 22:51:03
问题 I am unfamiliar with how Sublime Text 3 uses syntax highlighting, as in, if it purely relies on the theme or has it's built in standard that themes run off of but in my case, there's some syntax highlighting discrepancy with using PHP's HERE docs and forward slashes. Once a forward slash is present, it appears ST3 thinks all the following code is apart of that tag. Is this something I can fix? Forward slash syntax highlighting discrepancy No forward slash and correct syntax highlighting 回答1: