Questions tagged [command-substitution]

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

234 questions
1
vote
2 answers

echo $(command) gets a different result with the output of the command

The Bash command I used: $ ssh user@myserver.com ps -aux|grep -v \"grep\"|grep "/srv/adih/server/app.js"|awk '{print $2}' 6373 $ ssh user@myserver.com echo $(ps -aux|grep -v \"grep\"|grep "/srv/adih/server/app.js"|awk '{print $2}') 8630 The…
Bai Yang
  • 394
  • 2
  • 5
  • 17
1
vote
1 answer

Bash - is this called a definition?

I'm pretty new to bash, I learned about using variables like this: var=$(cat << EOF this is echoed and this as well... EOF ) echo "$var" if the above code is called using a variable how do you call the approach below? is this called a using a…
nath
  • 202
  • 3
  • 13
1
vote
1 answer

Extracting parts of whitespace seperated string

If have several Git repositories containing a file mergedriver.info This file looks always like this: A script, triggered by a Git merge driver, is evaluating this file: mergedriverinfo="$(git cat-file -p…
BlackEye
  • 775
  • 11
  • 25
1
vote
1 answer

bash - command substitution is omitting whitespaces

I have a command that is returning a string with a leading whitespace that gets eaten when I use command substitution > echo " test" test > echo $(echo " test") test Why is this happening and what can I do about it?
encomiastical
  • 143
  • 13
1
vote
1 answer

Where is $(< file) documented?

In bash it's possible to put a file as an argument using the form "$(< file)". Where is the documentation for the presumably special casing of $(
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
1
vote
1 answer

Bash: Insert variable content into command substitution as arguments - how to quote correctly?

I really really don't find a solution to this problem: Say I have a variable that has multiple lines, each line should be one argument in the end. line 1 line two ... I only get this data at runtime, but it should be build like this to an…
flix
  • 85
  • 7
1
vote
2 answers

Is there a "cleaner" way to substitute stdin into a string in Bash?

When bash scripting, I frequently find myself doing something like this: bc <<< "64*`cat`" or bc <<< "64*`dd`" if I want to multiply stdin by 64. Is there a better way to substitute stdin into a string (or into a command line, such as in seq 1 2…
markasoftware
  • 12,292
  • 8
  • 41
  • 69
1
vote
3 answers

Problems with command substitution (variable is empty)

Having some trouble with command substitution in a shell script. I've used this script before on another system, so not sure what's going on here. Seems like no matter how I enclose the commands to set the variable, I'm getting an empty variable.…
Ethan
  • 387
  • 1
  • 2
  • 13
1
vote
2 answers

Nest backticks inside a git command alias

I'm attempting to make a git alias to show all commits since the last tag. I'm basing it of this SO answer that I've used a lot in the past. Currently, I'm trying this with a git config --global alias.* command like so: git config --global…
matthewrdev
  • 11,930
  • 5
  • 52
  • 64
1
vote
1 answer

Adding a script/command/alias that uses command substitution

I have a command that I want to be able to run, and I will normally run it when my Mac starts up. The way I was trying to do it was to create an alias in ~/.bash_profile: alias b2dinit="boot2docker up && $(boot2docker shellinit) && boot2docker ssh…
mkobit
  • 43,979
  • 12
  • 156
  • 150
1
vote
1 answer

pipe/consume STDOUT as single string rather than sequence of whitespace separated words

I'd like to employ perl one-liner calculate resulting filenames using regexp substitutions. When doing dry run and simply printing the results it gives me the desired result (no quotes there yet): for i in *_\ *; do echo "${i}" $(perl -ne 'print…
1
vote
1 answer

Expanding parameters in Apache Ant exec task

I have a build that needs a task for starting a process, and one for killing it at the end. I have a file with the process id in it, but cannot figure out how to make ant expand the command substitution in order to pass the contents of that file to…
Bryan Agee
  • 4,924
  • 3
  • 26
  • 42
1
vote
1 answer

Do escaped double quotes in command substitution become literals in Bash?

If I execute this in Bash echo "1 2" I get 1 2. But if I execute echo \"1 2\" I get "1 2". Now I would figure if I execute echo $(echo \"1 2\") I would get 1 2. But again, I get "1 2". In fact, no matter how many command substitutions in the…
slicer
  • 13
  • 3
1
vote
2 answers

bash command substitution escaping

i want to get the result of the following command into a variable. xprop -name "google-chrome-stable" | grep "window id" | awk '{print $5}' | awk '{print $1}' the result should look something like that OUTPUT=xprop -name "google-chrome-stable" |…
divramod
  • 1,454
  • 2
  • 20
  • 35
1
vote
1 answer

fish: command substitution issue with interactive command

I'm trying to set "fzf - Fuzzy finder for your shell" for the fish shell. The problem is that interactive commands don't work when I use it in command substitution. Example: This command works: (echoes all the files in the current dir, and I can…
Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114