How to preserve line breaks when storing command output to a variable?

I’m using bash shell on Linux. I have this simple script … #!/bin/bash TEMP=`sed -n “””Starting deployment of”‘/,/'”Failed to start context”‘/p’ “/usr/java/jboss/standalone/log/server.log” | tac | awk “””Starting deployment of”‘/ {print;exit} 1’ | tac` echo $TEMP However, when I run this script ./ all the output is printed without the carriage returns/new lines. Not sure if … Read more

Run a string as a command within a Bash script

I have a Bash script that builds a string to run as a command Script: #! /bin/bash matchdir=”/home/joao/robocup/runner_workdir/matches/testmatch/” teamAComm=”`pwd`/” teamBComm=”`pwd`/” include=”`pwd`/server_official.conf” serverbin=’/usr/local/bin/rcssserver’ cd $matchdir illcommando=”$serverbin include=”$include” server::team_l_start=”${teamAComm}” server::team_r_start=”${teamBComm}” CSVSaver::save=”true” CSVSaver::filename=”out.csv”” echo “running: $illcommando” # $illcommando > server-output.log 2> server-error.log $illcommando which does not seem to supply the arguments correctly to the $serverbin. Script output: running: … Read more

Intersection of two lists in Bash

I’m trying to write a simple script that will list the contents found in two lists. To simplify, let’s use ls as an example. Imagine “one” and “two” are directories. one=`ls one` two=`ls two` intersection $one $two I’m still quite green in Bash, so feel free to correct how I am doing this. I just … Read more

choosing between $0 and BASH_SOURCE

How does one choose between “$0” and “${BASH_SOURCE[0]}” This description from GNU didn’t help me much. BASH_SOURCE An array variable whose members are the source filenames where the corresponding shell function names in the FUNCNAME array variable are defined. The shell function ${FUNCNAME[$i]} is defined in the file ${BASH_SOURCE[$i]} and called from ${BASH_SOURCE[$i+1]} 4 Answers … Read more

Passing bash variable to jq

I have written a script to retrieve certain value from file.json. It works if I provide the value to jq select, but the variable doesn’t seem to work (or I don’t know how to use it). #!/bin/sh #this works *** projectID=$(cat file.json | jq -r ‘.resource[] | select(.username==”[email protected]”) | .id’) echo “$projectID” [email protected] #this does … Read more