Command substitution is the replacement of a command with the result returned after it is evaluated.
Questions tagged [command-substitution]
234 questions
0
votes
1 answer
Using bash to generate random IPs in Curl
How to use random ip address in Curl request,I'm using this code and worked
printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))"
but when use this code in Curl request and test on http://ifconfig.me…

shadi ahmadian
- 37
- 4
0
votes
1 answer
The interpretation between the braces in the brace expansion
In Bash Beginners Guide Book
Brace expansion is performed before any other expansions, and any characters special to other expansions are
preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the…

Bahamas
- 5
- 2
0
votes
0 answers
Command substitution includes the text of a previous echo command
I have a script which writes some header info to the screen using 3 echo commands, then is supposed to delete a file that was previously created (and does exist). The file is a 6-digit text file, named with the format…

AlexC
- 3
- 2
0
votes
2 answers
How to apply multiple parameter expansion in BASH for a single output?
files=("Benjamin Johnson" "Bastin Johnson" "Bagio Johnson")
( IFS=','; echo "${files[*]/#/Mr.}"; echo "${files[*]/ /_}" )
Expected Result
Mr.Benjamin_Johnson,Mr.Bastin_Johnson,Mr.Bagio_Johnson
Output result:
Mr.Benjamin Johnson,Mr.Bagio…

Benjamin M.J
- 3
- 3
0
votes
2 answers
Deeply nesting commands
To escape characters in bash, Why the syntax is confusing when nesting commands deeply?, I know that there is an alternate approach with $() to nest commands, Just curious, why it is as such when nesting commands using backticks!
For example:
echo…

Aswath
- 96
- 4
0
votes
0 answers
Bash Command Substitution fail
I need some Specs and Data from Number of Latops in a ini-file.
When I try to get the IP-Adress with ip addr list nothing happens in the script. Not even a Error.
I try to quote stuff in my code. Nothing change.
for w2 in…

FlashGGG
- 5
- 2
0
votes
0 answers
Why can't a string variable be evaluated as a command when using ${!variable}?
This is somehow related to Use substituted string as a command in shell script I asked last year. That accepted answer worked nicely.
#!/usr/bin/env bash
for user in ytu
do
cd /home/${user}/H2-Data/crons
for path in "$user"_*_monthly_report.py
…

ytu
- 1,822
- 3
- 19
- 42
0
votes
1 answer
Bash Script not returning anything, using positional parameters
Running the script in-theory should output results per line depending on the arguments used
The scripts name is 'stdout', and have made it exacutable. I enter './stdout GOOGLE.COM' into the console and nothing happens
#!/bin/bash
if [ $# -lt 1 ];…

nathanjd
- 1
0
votes
0 answers
Bash: How do I read a plist value into a variable?
Using bash (on BSD Unix, mac):
#This successfully returns the plist value (YES or NO):
defaults read com.apple.finder.plist AppleShowAllFiles
#This does not work:
myVar=default read com.apple.finder AppleShowAllFiles
echo $myVar
What I am driving…

Brice Coustillas
- 2,363
- 2
- 13
- 18
0
votes
1 answer
Command with input redirection inside while loop
I am trying to loop inside a text file containing commands to be executed:
while IFS= read -r line
do
$line
done < msmtp-cmds.txt
The commands inside the text file are:
msmtp -t < message1.txt
msmtp -t < message2.txt
After…

Det
- 3
- 1
0
votes
1 answer
Bash pass date variable as string
I have a script which creates another script when run like this:
cat > "$installpath""tweets.sh" << ENDOFFILE
#!/bin/bash
source "$installpath"config.sh
cd \$webdir
/usr/local/bin/twint -s "\$search" --limit \$scrapelimit -o \$csvname --csv…

Niclas
- 89
- 9
0
votes
1 answer
Display output of command in terminal while using command substitution
So I'm trying to check for the output of a command, but I also want to be able display the output directly in the terminal.
#!/bin/bash
while :
do
OUT=$(streamlink -o "$NAME" "$STREAM" best)
echo "$OUT"
if [[ $OUT == *"No playable streams"* ]];…

doko
- 15
- 4
0
votes
1 answer
What is happening in this command substitution?
I have written the following command substitution and executed in in a bash shell:
$(echo echo 1; echo 2; echo 3) #output: 1 2 3
Why is the double echo required in the first expression, while only single echos are required in the second and third?

Display name
- 721
- 2
- 11
- 29
0
votes
0 answers
Bash, Systemd Service, command substitution - Not playing well together
I have the following in my redis@.service file:
...
ExecStop=/bin/bash -c \"/usr/local/bin/redis-cli -p $(echo %i | awk -F \'.\' \'{ print $2 }\') shutdown\"
...
Then when I run:
sudo systemctl stop redis@redis.6379.test-site.com.service
Followed…

Jack_Hu
- 857
- 6
- 17
0
votes
0 answers
How can one prevent a bash script continuing on error when using eval or command substitution
I have a bash script:
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Run a command
eval $(mycommand)
# Run another command
anothercommand
This script is called via SSH as follows:
ssh -o StrictHostKeyChecking=no -p 22 -l ${USER_NAME} ${HOST_NAME}…

David
- 7,652
- 21
- 60
- 98