Questions tagged [command-substitution]

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

234 questions
2
votes
3 answers

bash substitution call that increments a variable

I'm trying to define a bash function returning an incremented id that I can access directly using bash substitution: #!/bin/bash getId() { echo "$x" x=$((x+1)) } x=0 echo "id1: $(getId)" echo "id2: $(getId)" However the variable…
2
votes
2 answers

combining tilde expansion with variable substitution in bash

Say I'm running bash as root, and I want to chown the home directory of a user ada. Say also that ada is stored in a variable called $USER (because I'm doing this from a script). When I tried the following, chown -R $USER:$USER ~$USER the shell…
2
votes
1 answer

Shell hangs when assigning command result to a variable

My original problem was to kill a process & its children when timeout. And I found GNU timeout quite a good choice. However, in this testcase, things become weird: Assume that we have a test1.sh like this: #!/bin/sh # test1.sh output=`timeout 2…
sleepsort
  • 1,321
  • 15
  • 28
2
votes
2 answers

command substitution breaks command substitution

I extracted part of a shell script into another shell script, and for some reason after calling the sub-script, command substitution stops working. I can't imagine it's something in the sub-script, but I can't see what I'm doing wrong,…
Jayen
  • 5,653
  • 2
  • 44
  • 65
2
votes
2 answers

Shell sha1($salt.$password) error

I try to do something like this directly on my console as some testruns : It does not seem to work.. any idea what is the mistake I am doing salt="3245678906789045689" password="12321312231" blub=`sha1($salt.$password)` -bash: command substitution:…
user1524529
  • 897
  • 3
  • 10
  • 12
1
vote
3 answers

Bash Script Command Redirection/Reuse -- How to Accomplish Multidirectional Layered Redirection?

I'm struggling to understand command redirection/reuse... I understand there's the <(...) <(...) methodology and the $( ... && ... ) techniques for combining output. But I don't really fully understand what the difference is (I realize that the…
Jason R. Mick
  • 5,177
  • 4
  • 40
  • 69
1
vote
2 answers

Order of Command substitution and Arithmetic expansion in bash

The book “Learning the bash Shell” 3rd ed. by Cameron Newham and Bill Rosenblatt has at page 181 a picture describing the command-line processing of bash shell. That picture shows that Command substitution is performed before Arithmetic substitution…
1
vote
1 answer

assign output of a cat | sed | awk to an array

Updated Question with code. I have written a script that retrieves files from a remote server via scp. Then I want the script to delete the success file that has been retrieved. But instead of removing the successful file I want to put it into an…
goced
  • 61
  • 2
  • 9
1
vote
1 answer

how do I get rid of the single quotes around my string

I have a zsh script. There is a function ... imgPrep() { local inFilePath=$1 local outFilePath=$2 local cropHeight=$3 local resize=$4 shift; shift; shift; shift local options=$@ convert ${inFilePath} -crop 0x${cropHeight}+0+0 +repage -resize…
1
vote
0 answers

Bash Script IP Variable Output Issue

I am making a Bash script that randomly generates and then try's to connect to an IP address. I cannot figure out how to make the SSH variable work to connect to the listed IP addresses. for i in {1..100} do STR="printf "%d.%d.%d.%d\n" "$((RANDOM %…
CKJones
  • 11
  • 2
1
vote
2 answers

How to create a variable with error going to /dev/null

I am not able to redirect an expected error to &>/dev/null in the following simple code. xml=`ls ./XML_30fps/*.xml ./XML_24fps/*xml` The expected error is due to the fact that one of the folders could be empty and so the error would be "No such…
Robin
  • 339
  • 1
  • 9
1
vote
1 answer

Linux command execution in different process and sending their results in variables

I'm trying to create a Bash script to calculate MD5 checksum of big files using different process. I learned that one should use & for that purpose. At the same time, I wanted to capture the results of the check sum in different variables and write…
TRANSISTOR
  • 13
  • 3
1
vote
0 answers

How to I capture Echo outcome into a variable in BASH script?

We are trying to run a BASH script in IBMi system , one of our use case is to execute a CL program from Bash script that will copy sources from IFS to Library. We need a way to capture copy outcome and then perform some additional business logic in…
Digvijay
  • 41
  • 2
1
vote
1 answer

How to use powershell to get the next word, in this case it's number, from a specific word in the output

How to use powershell to echo the next word, in this case it's number, from a specific word in the output For example this command powershell echo "$(chia wallet show -w standard_wallet | Select-String -Pattern "Spendable:") Gives this line that…
1
vote
2 answers

Write the outcome of a for loop in multiple files in a single file in shell

I am new to shell scripting (bash/awk...etc) so please excuse me for my stupid question. I am aware that to many of you this is so easy I have multiple files that look like this: file1.bam, ...., file1000.bam and for each one of the files I am…
LDT
  • 2,856
  • 2
  • 15
  • 32