Questions tagged [command-substitution]

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

234 questions
0
votes
0 answers

Setting a variable within command substitution

I'm trying to get both the HTTP code and the output of a curl command as part of a shell script, but in turn I'm trying to set both of them as variables. My code (which uses the pushbullet API) looks like this: CURL_OUTPUT="$(exec 3>&1; \ …
Roger Filmyer
  • 676
  • 1
  • 8
  • 24
0
votes
2 answers

sed: How to use a remembered pattern in an embedded shell command?

I have a GNU makefile with one of the recipe lines reading: sed -i 's|$$\(.*\)$$|'"$$(curl -d "type=tex&q=\1" http://localhost:16000/)"'|g' $(NAME).a4.xhtml The idea is to replace
Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
0
votes
2 answers

Substitute command into remote sed command

I want to write a Unix command which select a random user from /etc/passwd and check a remote host using SHH to determine if a user with the same UID exists, print out the full line from passwd if the user exists. Here is the command I wrote so…
Haka
  • 1
0
votes
3 answers

Reading the path of files as string in shell script

My Aim --> Files Listing from a command has to be read line by line and be used as part of another command. Description --> A command in linux returns archive/Crow.java archive/Kaka.java mypmdhook.sh which is stored in changed_files variable. I…
Naveen Dennis
  • 1,223
  • 3
  • 24
  • 39
0
votes
3 answers

Pass variable in awk inside command substitution

I am new at this and is learning how to get the variable. How do i get print variable parts right inside command substitution? Thanks. echo "Enter number of parts:" read parts echo "Enter filename:" read filename LINES=$(wc -l $filename | awk…
Potential Coder
  • 91
  • 3
  • 11
0
votes
1 answer

Command substitution and undone background tasks

Is there a way to force command substitution to exit leaving baground task undone? Example: cat test.sh #! /bin/bash sleep 5 & echo "foo bar" Running it without command substitution: time bash test.sh foo bar real 0m0.005s user 0m0.005s sys…
Tiago Lopo
  • 7,619
  • 1
  • 30
  • 51
0
votes
2 answers

Grouping command substitution without double quotes? "$()" without the ""

I'm writing a script that involves generating Awk programs and running them via awk $(...), as in [lynko@hephaestus] ~ % awk $(echo 'BEGIN { print "hello!" }') The generated program is going to be more complicated in the end, but first I want to…
Evelyn Kokemoor
  • 326
  • 1
  • 9
0
votes
0 answers

Bash command substitution freeze

Currently I encountered the following situation when bash script freeze on PID=`cat test.pid` After the analysis it was found that even this commands freeze TEST=$(echo 1) TEST=`echo 1` Using set -x in bash script, I can see the following output +…
Ilya
  • 101
0
votes
2 answers

bash command substitution force to foreground

I have this: echo -e "\n\n" find /home/*/var/*/logs/ \ -name transfer.log \ -exec awk -v SUM=0 '$0 {SUM+=1} END {print "{} " SUM}' {} \; \ > >( sed '/\b0\b/d' \ | awk ' BEGIN {printf "\t\t\tTRANSFER LOG\t\t\t\t\t#OF HITS\n"} …
menders65
  • 43
  • 8
0
votes
2 answers

Using substitution for execute methods c#

I'm new in C# and I need some hints to solve this problem: I start to develop an application in C# an Windows Form Application (until this summer, I work 20 years in Visual Fox) The UI is generic (has an grid and controls for show details for…
Bogdan
  • 656
  • 15
  • 25
0
votes
3 answers

Command substitution as a variable in one-liner

I get the following error: > echo "${$(qstat -a | grep kig):0:7}" -bash: ${$(qstat -a | grep kig):0:7}: bad substitution I'm trying to take the number before. of > qstat -a | grep kig 1192530.perceus- kigumen lr_regul pbs.sh …
kirill_igum
  • 3,953
  • 5
  • 47
  • 73
0
votes
2 answers

Using AWK to read line from file and create a variable

I have a text file with a list of filenames. I would like to create a variable from a specific line number using AWK. I get the correct output using: awk "NR==\$Line" /myPath/fileList.txt I want to assign this output to a variable and from…
Sara
  • 1
  • 1
  • 1
  • 3
-1
votes
1 answer

How to install new package version (update package) when there is new update available in repo using shell script

I need to write a shell script that upgrade a package by comparing installed and available version. For example git 2.3 is installed in my machine, I need to upgrade to new version (if available) through shell script. I tried…
-1
votes
2 answers

Get json value using regex in linux

I have a json file file.json like this: { "abc": "123", "def": 456, "ghi": 789 } I am trying to get value of all the keys using regex in bash terminal. Here is what I tried for getting value of abc: var=cat file.json regex='(abc\":)…
mmk
  • 480
  • 3
  • 10
-1
votes
1 answer

Why does command substitution with a command in front e.g. eval interprets the string as literal zsh commands to execute?

I was going through this What is the use of eval `opam config env` or eval $(opam env) and their difference? and notice something funny. I understand command subtitution is used to nest commands in zsh by evaluating a zsh cmd in a subshell and then…
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
1 2 3
15
16