Questions tagged [command-substitution]

Command substitution is the replacement of a command with the result returned after it is evaluated.

234 questions
1
vote
5 answers

Prepend printed string with its final newlines to a bash variable

I have the following function defined in bash: function print_revision { printf "Revision %s (%s)\n%s\n\n" "$1" "$(date --utc +%d.%m.%Y,\ %H:%M\ UTC)" \ "----------------------------------------" } I also have a variable, $CHANGES with some…
linkyndy
  • 17,038
  • 20
  • 114
  • 194
1
vote
2 answers

BASH: SSH into server, query MYSQL Funny stuff

I am having some trouble with a script of mine that is supposed to SSHs into my server, run a mysql query, and return a specific value. My problem is that I am getting an Access Denied error when I use command substitution [ $() and `` ] - but…
JHAWN
  • 399
  • 4
  • 18
1
vote
4 answers

Does awk -v accept command substitution?

Can I create an awk variable in a one liner using bash command substitution techniques? Here is what I am trying, but something is not right. awk -v AVG=$(uptime|awk '{print $(NF-2)}') '{ if ( AVG >= 1 ) print "there is a load" }' Perhaps it's…
GL2014
  • 6,016
  • 4
  • 15
  • 22
1
vote
1 answer

How to combine command substitution and regex?

Is there a possibility to do command substitution in a regex? I want to find files in Linux with specific names. The name may include fix strings, but it may also only include the hostname. So what i want to do is something like: find /home/ -type f…
Tim Zimmermann
  • 6,132
  • 3
  • 30
  • 36
1
vote
1 answer

Bash Command Substitution with Variables

I have a bash script that builds a command based on a list of files so the command is built on the fly. Building it on the fly means it gets stored in a variable. I then want to run that command and store the output in a separate variable. When I…
1
vote
1 answer

check directory of oracle logs

I'm using the check_logfiles nagios plugin to monitor Oracle alert logs. It works wonderfully for that purpose. However I also need to monitor and entire directory of oracle trace logs for errors. This is because the oracle database is always…
bluethundr
  • 1,005
  • 17
  • 68
  • 141
1
vote
2 answers

Interpreting command substitution from a variable in bash

For the following value of FOO: $ FOO='echo `echo hello`' $ $FOO `echo hello` how can I get the expected output: hello Basically, how can I interpret a command substitution in the contents of a variable?
umop
  • 2,122
  • 2
  • 18
  • 22
1
vote
1 answer

Order of substitution in bash

I need to demonstrate the order in which command substitution, variable substitution and globbing occurs. Any ideas on how to do it?
SharkTiles
  • 585
  • 3
  • 9
  • 22
1
vote
2 answers

bash command substitution: find command with wildcard in single quotes

I want to dynamically construct a "find" command and see whether it returns anything. This is the minimised example. In a directory containing files, find . -name '*' of course returns the files. But VAR="find . -name '*'" $VAR returns nothing.…
cato_minor
  • 663
  • 6
  • 11
1
vote
1 answer

pgrep prints a different pid than expected

I wrote a small script and for some reason I need to escape any spaces passed in parameters to get it to work. I read numerous other articles about people with this issue and it is typically due to not quoting $@, but all of my variables are…
0
votes
1 answer

Prevent shell command substitution

Is there a way to prevent command substitution in a shell script? For instance, if the script contains a line like: var=`echo foo` I would like a way to get `echo foo`. Not just the substitute of the command which is foo. Edit: I am trying to…
K. Smanis
  • 1
  • 1
  • 2
0
votes
1 answer

How can I nest $(var) variable command substitutions?

I have a need to update a bash/perl script to create a file with a system process (mktemp), I need to set the filename for creation, and for this I want to use the current system date: LOGFILE=$(/bin/mktemp /folder/program_log.$(date +'%Y%m%d')) I…
Martin
  • 22,212
  • 11
  • 70
  • 132
0
votes
0 answers

Bash script regex on parameter

I have a script like this: #!/bin/bash …
vaso123
  • 12,347
  • 4
  • 34
  • 64
0
votes
2 answers

Kubernetes CronJob - Escaping a cURL command with nested JSON and command substitution

I have the following Kubernets CronJob definition: apiVersion: batch/v1 kind: CronJob metadata: name: myCronJob spec: schedule: "*/1 * * * *" failedJobsHistoryLimit: 1 successfulJobsHistoryLimit: 1 jobTemplate: spec: …
0
votes
0 answers

BASH: Variables in a function piped to dialog are lost

I have a script with a function which does some stuff and sets some variables to be used later in the script. This function is also echoing progress (echo 10, echo 20 etc.) and is piped to a "dialog --gauge" to display a progress bar. After the…