The tag has no usage guidance.

learn more… | top users | synonyms

3
votes
3answers
46 views

set variable inside heredoc and use them outside

I'm trying to set the variable 'count' while running the command inside a heredoc together with timeout, but I'm unable to get the 'count' variable outside the heredoc. How can I achieve that? My ...
1
vote
2answers
55 views

Grep command using contents of a heredoc

I'm creating a script to update a remote computer and I want to know if any user is using the computer before I update. I have a list of users and I created a heredoc with all of them. The command I'm ...
1
vote
1answer
44 views

Any way to create Here Documents that substitute some variables but not others in bash?

I was wondering if there any way to create a here document in bash to output to a file within a script, problem is that in this config file I am trying to output some variables that start with $ I ...
3
votes
0answers
70 views

How to get bash tab completion to work with read only file system?

I have deliberately configured the file system of my RaspberryPi (Raspbian - Jessie) to be read only. One of the things that's not (yet) working is tab (aka auto) completion in bash, where I often get ...
1
vote
1answer
67 views

How to escape a range of wildcards in unix shell script?

I need to execute the following Oracle SQL in unix crontab. The query is as follows: select count(*) from tbaadm.htd where cust_id is not null and pstd_flg = 'Y' and del_flg = 'N' and tran_date = ...
1
vote
1answer
93 views

Is it possible to do a here-document in one line or echo verbatim?

I often find myself testing out a command (e.g. cat file | awk 'stuff') in the shell and when I'm satisfied with the way it works, I append the command to a script file. Let's say this is the command ...
2
votes
1answer
251 views

How to set heredoc output to local variable

I'm trying in a heredoc to set its output to a local variable as follows : REMOTE_OUTPUT=$(ssh remote@server /bin/bash << EOF find my/path/ -type f -not -path my/path/*/ -type f -mtime -0 | ...
2
votes
2answers
86 views

For input redirection, are there functional differences between bash/zsh <<<“$(<file)” and the traditional <file?

I'm asking only about the usage which would have the similar effect as traditional input redirection from a file. <<<"$(<file)" as far as I can tell is equivalent to <file It ...
2
votes
2answers
65 views

Get path of here document as a file

I have a program that takes input from an XML file whose path is specified as a parameter. I want my shell script to be self contained, so a here document seems like the right way to go. ...
0
votes
3answers
55 views

Where do people use the “Here document” on UNIX systems? [duplicate]

Where do people use the "Here document" on UNIX systems? Where is it used in reality?
1
vote
1answer
427 views

Set variable inside heredoc, use variable outside heredoc

I've got the following in a bash script ssh -T -i ${ssh_key} ${ssh_user}@${host} <<- 'EOF' file=`hostname`.tar.gz echo "file: " $file ### prints>> file: some-host-name.tar.gz EOF ...
0
votes
1answer
722 views

Why is bash confusing this HEREDOC limit string as a command?

I am trying to use nested HEREDOC blocks in a bash script. Note The outer HEREDOC is user to run a list of commands as a different user via sudo the inner HEREDOC is capturing regular text to cat ...
0
votes
0answers
76 views

Multiple here documents in a bash script to drop in and out of sudo is causing error “Sessions still open, not unmounting”

I'm attempting to write a setup script that I can run on multiple machines to run a bunch of installers (requires sudo) but also do things like pull down a git repo (I want to run that as the normal ...
1
vote
1answer
40 views

Here Document on Platform LSF

I am trying to perform process substitution within a command passed to Platform LSF via bsub. On the worker node that I submit my job to, process substitution is not enabled because it is not a POSIX ...
2
votes
1answer
63 views

View remote value of $PATH inside shell script

When executing this bash script, it only shows my local path. ssh ${REMOTE_HOST} 'bash -s' <<EOL set -e source ~/.profile echo $PATH # Commands here don't work because $PATH is ...
6
votes
3answers
516 views

Why does `cat` seem to iterate over JSON arrays?

I'm puzzled by this behaviour of cat when trying to output a heredoc containing JSON in bash 3.2: input: $ cat <(cat <<EOF > {"x":[{"a":1,"b":2}]} > EOF) output: {"x":["a":1]} ...
12
votes
3answers
997 views

How to understand “cat > file_name << blah” command?

In following command cat takes the content of here-doc and redirects it to file named conf: cat > conf << EOF var1="cat" var2="dog" var3="hamster" EOF How to understand the order of ...
2
votes
3answers
909 views

Pasting some text with tabs into a here-document in a PuTTY window

I have a string with tab delimited data that looks like: h1 h2 a1 b1 a2 b2 I produced it with Notepad on Windows. I created tab delimited data, ensuring that tabs and not spaces are used. I ...
0
votes
0answers
169 views

Avoiding heredoc sh[process_number].* files in /tmp directory

I have a .ksh file which logs into sqlplus and runs some queries. The block of code is something as mentioned below: //Other things done in ksh sqlplus -s @connect.sql << EOF Query1 Query2 ...
6
votes
2answers
345 views

How can I end a here-document that starts with <<\\$fff?

I was asked the following question in a test on shell scripting at my university, which never gave an answer, and google is of little help. Q: What is the line separator that should be used to end ...
4
votes
4answers
701 views

How to cat two heredocs? [duplicate]

When cat is given two heredocs, it only outputs the second one. $ cat <<HERE > adsf > qwer > HERE adsf qwer $ cat <<HERE <<ALT > qwer > asdf > HERE > zxcv > ...
2
votes
1answer
659 views

cat to stderr while reading to end of file marker

Leaving aside the question of whether usage output should go to stderr or not, if you had to redirect the output of the cat command below to stderr, how would you do it? function usage { cat ...
1
vote
1answer
153 views

decrypt and unarchive file embedded in the script

I'm trying to create a self-extracting encrypted archive. Here's code that doesn't work for me: openssl enc -aes-256-cfb -salt -d -a | tar -x -j <<EOF ...
2
votes
1answer
178 views

Indented here document causes a syntax error

I have the following code fragment in my shell script and have a bug that I can't seem to pin down a reason for despite some research. When I run the code as below the script exits with a message ...
1
vote
1answer
303 views

ksh “<<EOF” script to change user

In the simplest form I am puzzled why this script does not work as expected as a here script changing users with su - user <<EOF. su - db2prd<<EOF PARMDATE=1111111 echo parmdate echo ...
0
votes
1answer
230 views

How could I include a variable in a here document?

I am trying to use a user-defined global variable in a cat <<eof>> filename situation, but it's not working. I found what I want in simple cat << eof examples on this forum, which ...
0
votes
1answer
249 views

create a user via script

I want to create a new user in a specific group when I issue the below command. sudo ./create_user.sh "test" "firstname lastname" The create_user.sh script looks as below. #!bin/bash #sudo ...
3
votes
1answer
405 views

How to redirect output while using a here document

How to redirect the output of below command in shell into logfile. sqlplus -s "/nolog" <<EOF conn / as sysdba @?/sqlpatch/19282021/postinstall.sql exit; EOF
3
votes
1answer
727 views

What are the bash shell length limitations for here-docs?

What are the length limitations for using here-docs as part of bash command lines? I am finding that short here-docs work fine, but when they get longer there is some point or structure after which ...
4
votes
3answers
731 views

Can you source a “here document”?

Let's say I have a bash script that acts as a config file for another bash script: config.sh: verbose=yes echo "Malicious code!" name=test script.sh: source config.sh echo "After sourcing: ...
1
vote
1answer
359 views

What does this `cat` statement do?

I'm new to Linux and trying to figure out what this statement in a Bash file does. I think it combines stdout, stderr and output it to the file $log is pointing to and append the multiline string to ...
1
vote
2answers
550 views

awk - read program AND input from the standard input?

Is it possible for awk to read the program and the input from the standard input? I would like to be able to pipe a file to the following function. process_data () { awk -f - <<EOF {print} ...
11
votes
1answer
705 views

Is it possible to use multiple here-docs in bash?

Can one use multiple here-docs to provide input to a command in bash? $ cat <<<foo <<<bar bar $ cat <<EOF1 <<EOF2 > foo > EOF1 > bar > EOF2 bar Obviously, ...
0
votes
3answers
596 views

Why does passing a HEREDOC as a string to `ruby -e` not work?

For reasons I don't understand, it seems to be impossible to pass a heredoc as an expression to a Ruby interpreter: $ ruby -e <<END heredoc> puts 'hi' heredoc> END ruby: no code ...
0
votes
2answers
11k views

Passing a variable to a bash script that uses 'EOF' and considers the variable a literal [closed]

in this script i end up with "$1" being saved to the /test file. #!/bin/bash cat > /test << 'EOF' $1 EOF the truth is.. i need to keep 'EOF' as 'EOF' because my argument($1) contains ...
2
votes
2answers
1k views

“cat” command: how to automatically escape everything that might be a violation?

If you copy the contents of httpd.conf and then paste it into a cat command.. such as this one.. #!/bin/bash cat > /test << EOF pasted here.. EOF you run into this error: -bash: ...
1
vote
0answers
26 views

How to combine Bash's read with HERE-document when shopt -os errexit is in place? [duplicate]

I am trying to make use of the solution presented in one of the answers of http://stackoverflow.com/questions/1167746/how-to-assign-a-heredoc-value-to-a-variable-in-bash In Bash version ...
9
votes
3answers
792 views

How to combine Bash's process substitution with HERE-document?

In Bash version 4.2.47(1)-release when I try to catenate formatted text that comes from a HERE-dcoument like so: cat <(fmt --width=10 <<FOOBAR (I want the surrounding parentheses to be part ...
1
vote
1answer
162 views

Using cat to modify ~/.bash_profile seems to remove __git_ps1 compeltely

I want my prompt to display the current git-branch when inside of a repo directory. e.g., [desktop repo(master)]$ In my terminal I can type: cat <<EOF >> ~/.bash_profile ...
4
votes
6answers
5k views

Remove last comma from a bash for loop generated string

I am dealing with a situation where I need to create a comma separated list from an array into a heredoc and remove the last comma. I am using bash for piped into sed which is erasing all commas ...
-3
votes
1answer
2k views

Shell script- syntax error: unexpected end of file [closed]

I'm practicing some scripts from a book and I keep getting an unexpected end-of-file syntax error. The images below show the error message and the script that uses basic commands to create a ...
1
vote
2answers
1k views

Auto answering password for OPENSSL using HEREDOC [closed]

I have the following command but it doesn't work for me... cd /etc/postfix/ssl/ && openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024 <<PASS password password PASS The output ...
4
votes
4answers
30k views

How to login as root from Bash and do stuff

This is my simple bash: cat test.sh #!/bin/bash echo "hello" su - root -c /path/to/script.sh <<EOF password EOF whoami echo "good bye" But I get this error: ...
2
votes
1answer
176 views

< and << in UNIX /Linux [duplicate]

What are the operators <<and < used for in Linux? For example cat << abc.txt
1
vote
1answer
292 views

Cat write text with “$” inside

I want to write configuration information to a specific file which has dollar signs ($) inside. That seems to be a problem. Here's what I did: $ cat >> /etc/nginx/nginx.conf <<EOF # For ...
1
vote
1answer
549 views

Execute command on remote host fails

I'm trying to execute some commands on remote host like this : ssh -t -t -l user 172.20.20.20 <<EOF pid=$(ps -ef | grep [a]pp-management | awk '{print $2}') && kill -9 $pid && ...
10
votes
3answers
421 views

bash: Some issue when using read <<<“$VARIABLE” on a read-only root partition. Any known workarounds?

Just by coincidence I had to use my ATA-ID-to-device-name script (found here: http://serverfault.com/questions/244944/linux-ata-errors-translating-to-a-device-name/426561#426561) on a read-only / ...
2
votes
2answers
1k views

setting variables inside subshell when using <<

I am using the following method in order to pass commands into a subshell that is started by "newgrp". #!/bin/csh echo "Before newgrp" /usr/bin/newgrp users <<EONG echo "hello from within ...
7
votes
1answer
8k views

How to echo variables using cat into file?

I have simple script like this: #!/bin/bash BOO=bla-bla-bla cat > ./Makefile <<'EOF' Hello INCLUDES := -I/data/opt/include/ -Ideps/ -I$BOO/include EOF Yet it outputs into ...
15
votes
1answer
11k views

How do you use output redirection in combination with here-documents and cat?

Let's say I have a script that I want to pipe to another command or redirect to a file (piping to sh for the examples). Assume that I'm using bash. I could do it using echo: echo "touch somefile ...