Questions tagged [command-substitution]

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

234 questions
0
votes
1 answer

Shell script when we need to quote or unquote

I am trying to understand in what situation we should use quote the command while parsing the output from it or when should not. bash Case 1: I am using below command into my bash script which works well while using like below which results the…
user2023
  • 452
  • 5
  • 22
0
votes
3 answers

BASHRC PS1 show datetime but plus 3 hours

Every of us set own convenience working with Linux shell, for example I use /root/.bashrc PS1='[\h:\w] \D{%F %T}\n\$ ' to show servername + current server datetime + newline for command - so it looks like [servername217:~] 2022-02-06…
Serge
  • 679
  • 1
  • 9
  • 23
0
votes
2 answers

How effectlively to call a bash function to another in a program

I have below Bash script where I am trying to Create functions for creating colors for output text in the script, I am trying to call these function into another one but somehow its not working. I looked around and googled, but didn't get the…
user2023
  • 452
  • 5
  • 22
0
votes
2 answers

bash zip file with version read from file and used in zip file name

I'm able to zip a bunch of files with zip $ zip build.zip src/*.js src/assets/icons/*.png *.json updating: src/addReactionsNav.js (deflated 65%) updating: manifest.json (deflated 55%) updating: src/assets/icons/icon_128.png (stored 0%) updating:…
Norfeldt
  • 8,272
  • 23
  • 96
  • 152
0
votes
1 answer

Bash - optionally set env var in command substitution

The following works without issue: timestamp=$(TZ=America/New_York date) echo $timestamp which (if saved in a file called /tmp/foo) results in: $ /tmp/foo Thu Dec 23 21:03:41 EST 2021 This code also works: timezone=$1 timestamp=$(TZ=$timezone…
Joe Casadonte
  • 15,888
  • 11
  • 45
  • 57
0
votes
1 answer

How to count amount of pull request made by user?

I have bash sript pull.sh with one argument is github nickname of a person. And I want to count amount of all pull request which was made with this nickname. I select pr this way in command line: curl -s…
Vivern202
  • 29
  • 3
  • 7
0
votes
1 answer

Conditional `if` statement with strings in shell script to configure two computers differently (Ubuntu/Gnome vs Debian/XCFE)

I want to check the current distro in .profile because I have two computers. In one I have Ubuntu with Gnome, and in another I have Debian with XFCE. In either case I want to have different configurations, but I can't manage to even get the…
0
votes
1 answer

Simple question about ls output and Double quotes

I'm learning bash so this is a simple question probably. I'd like to understand what happens in this case, there's no real use for this script. Let DTEST be a directory that contains some random files. for filename in " `ls DTEST/*` " ; do …
user14356197
0
votes
1 answer

why function variable not working in command substitution inside a function?

im running this in bashrc file function simplefunc () { output=$(ls -1 "$HOME") linecount=$(${output} | wc -l) echo "${linecount}" echo "${output}" } getting this error Desktop: command not…
0
votes
2 answers

File count in a folder not showing accurate

I am writing a shell script to check two things at one time. The first condition is to check for the existence of a specific file and the second condition is to confirm that there is only one file in that directory. I am using the following…
Devil's Dream
  • 655
  • 3
  • 15
  • 38
0
votes
1 answer

Passing output of bash expression to variable piped through a dialog progressbox results in null value for the variable

I am using dialog Version: 1.3-20190211 wiht GNU bash, version 5.0.3(1)-release and have the following script snippet which scans for networks on wlan0. #!/bin/bash # duplicate file descriptor 1 on file descriptor 3 exec 3>&1 # Scan for networks…
0
votes
1 answer

How to read in current process with here document

I would like to read in the current process: mark=one read a b c <<<$(grep "^$mark " <
blueFast
  • 41,341
  • 63
  • 198
  • 344
0
votes
0 answers

Bash command substitution within a function does not return the return code from the command substitution

I find that within a function, using command substitution to put the command output in a variable, using $? to get the exit code from the command substitution returns 0, not the returned code. The command substitution returns the return code as…
0
votes
1 answer

Building filename from command outputs results in ambigous redirect error

I want to edit a file and write it to anoter location without .template at the end. To do so, I use two commands in a row which should give me the new file name, but bash doesn't accept it. I heard you should do this with backquotes but I can't get…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
1 answer

Single < next to filename in bash

I'm trying to make sense of this application of the sed command: sed -f <(printf 's/%s/%s/g\n' $(newcontents.txt In particular I don't quite understand what
glades
  • 3,778
  • 1
  • 12
  • 34