Linked Questions
15 questions linked to/from What is command substitution in a shell?
266
votes
6
answers
498k
views
What does ` (backquote/backtick) mean in commands?
I came across the following command:
sudo chown `id -u` /somedir
and I wonder: what is the meaning of the ` symbol. I noticed for instance that while the command above works well, the one below does ...
1
vote
1
answer
628
views
How do i print the path of excuatable in echo [duplicate]
SO i have a Bash Script like this and goal is to determine the path of an executable file and i want to print it, here is what i'm doing
#!/bin/bash
exepath=which exe
echo "$exepath"
Now ...
292
votes
6
answers
47k
views
What's the difference between $(stuff) and `stuff`?
There are two syntaxes for command substitution: with dollar-parentheses and with backticks.
Running top -p $(pidof init) and top -p `pidof init` gives the same output. Are these two ways of doing the ...
86
votes
3
answers
31k
views
Is $() a subshell?
I understand the subshell syntax to be (<commands...>), is $() just a subshell that you can retrieve variable values from?
Note: This applies to bash 4.4 based on different wording in their ...
27
votes
7
answers
13k
views
Is the "callback" concept of programming existent in Bash?
A few times when I read about programming I came across the "callback" concept.
Funnily, I never found an explanation I can call "didactic" or "clear" for this term "callback function" (almost any ...
18
votes
2
answers
5k
views
Difference of using () and $() to execute a series of commands
I am currently trying to make a script that creates bytes that will be piped as input to netcat.
Here is the idea of the script:
(perl -e "print \"$BYTES\x00\";
cat file;
perl -e "print \"More ...
3
votes
1
answer
4k
views
Script function call: function vs $(function)
Taking how reference the following code for simplicity
#!/bin/bash
number=7
function doSomething() {
number=8
}
doSomething
echo "$number"
It prints 8.
But with:
#!/bin/bash
number=7
...
2
votes
5
answers
331
views
What problem/pattern justifies using command substitution?
I raised a few server environments with Ubuntu and Bash, on "self managed shell" hosting providers like DigitialOcean, on which I ran Drupal/WordPress applications.
All that time I didn't have a ...
1
vote
2
answers
7k
views
USB reset using lsusb output
I have a USB device that I wish to reset automatically, there are two USB devices currently, but at times there may be more.
[user1@gs10 devt]$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation ...
5
votes
2
answers
9k
views
What is "Parameter expansion" (A.K.A "Variable expansion") in shell-scripting in general and in Bash in particular?
I understand the term "Parameter expansion" (A.K.A "Variable expansion") to be an umbrella term for several unrelated operations in shell-scripting in general and in Bash in particular, such as:
...
3
votes
1
answer
2k
views
Weird behavior in zsh random generator
I have this script to generate $1 digit(s) of mixed random char from the defined charlists as arrays.
#!/bin/bash
charlist1=(a b c d e f g h i j k l m n o p q r s t u v w x y z)
charlist2=(0 1 2 3 4 ...
0
votes
2
answers
3k
views
Create bash prompt that shows the directory after my home directory
For example, if my home directory is 'FirstLast' and I am inside of
/usr/FirstLast/Dir1/Dir2/Dir3
I want my prompt to read
[username@srv1 Dir1]
regardless of how deep in my directory I am. So the ...
0
votes
1
answer
497
views
Add prefix backslash and quotes to comma separated columns in shell script
Need to convert the below string to add prefix backslash and suffix backslash for comma separated columns. String values can be dynamic values (some times we get two comma separated values or three ...
0
votes
1
answer
152
views
Syntax Question for Bash using pipes
I am trying to set a variable to a value returned by a program (lynx). I cannot get past which parenthesis or bracket I use to accomplish my goal.
I have this:
DEBFILE=${(lynx -listonly -dump https://...
0
votes
1
answer
215
views
How to take the number including dot from an output of one command and use it in another one?
How to take the number including dot from an output of one command and use it in another one?
For example, this command
chia wallet show -w standard_wallet
gives this result
Wallet height: xxxxxx
...