Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [command-substitution]

Questions about shell command substitution (such as $(command) or `command`), its mechanism, correct syntax etc. Not to be confused with aliasing.

Filter by
Sorted by
Tagged with
0 votes
2 answers
128 views

So, I was playing around with this answer, when I found that neither printf_stdin () { read input printf "$input" } sed "/lorem ipsum foobar/ { s/'/'\"'\"'/g s/\...
Grass's user avatar
  • 145
2 votes
1 answer
521 views

how do you supply a literal asterisk * when specifying a filename to a command substitution in bash? Consider the following directory: host:/tmp/backtick-test# ls -l total 0 -rw-r--r-- 1 root wheel ...
Scott's user avatar
  • 103
0 votes
2 answers
88 views

The following question likely does not relate specifically to Vim. I use a Vim example, as this is where I encounter the issue. Working on Ubuntu, I often open multiple files in Vim using tab pages: $ ...
user7543's user avatar
  • 266
1 vote
1 answer
141 views

I'm trying to break a long command substitution on to multiple lines, as discussed in this answer. In a plain command pipeline, both explicit (\) and implicit line continuation work fine: $ echo 'blah ...
Jacktose's user avatar
  • 532
0 votes
1 answer
74 views

I have a file named fileWithOneCommand.txt with just one command as follows ps -aux|head -n 5 then I write a testing shell script named 'test5.sh' with content as follow: file=/home/somepath/...
user1169587's user avatar
0 votes
1 answer
49 views

I am doing a code-study of /lib/lsb/init-functions on mint 20 just to familiarise myself with SystemV init system. There is log_action_end_msg function in it which has this code snippet, TPUT=/usr/bin/...
Saravana's user avatar
  • 193
-4 votes
1 answer
127 views

So doing $(cat /etc/passwd) results in "No such File or Directory" and "$(whereis cat)" results in "command not found" Why is command substitution not working in the ...
jstar100x's user avatar
0 votes
1 answer
135 views

in bash i will run a script that take a look in the folder folder123/ to know how much space is requered for the files they are in there. but this requered value will i multiplie with 1,5 and than ...
user447274's user avatar
1 vote
1 answer
102 views

I have the following simple shell command: for x in $(echo one two three); do echo $x; done When executed, it simply prints one two three on one line, i. e. the result of the command substitution is ...
René Nyffenegger's user avatar
0 votes
1 answer
83 views

I am trying to pass filenames retrieved from everything voidtools via their es.exe command line (it works similarly to mlocate) to an "image previewer" like gwenview or nsxiv (in wsl ...
Daniel Krajnik's user avatar
0 votes
0 answers
50 views

I'm trying to pass a list of image files to open gwenview. The only way that seems to work is to list them on command line. However, some file paths have spaces, so they have to be additionally quoted....
Daniel Krajnik's user avatar
0 votes
3 answers
133 views

I am trying to normalise a data file using the number of lines in a previous version of the data file. After reading these questions, I thought this could work: awk -v num=$(wc -l my_first_file.bed) '{...
Whitehot's user avatar
  • 245
0 votes
2 answers
104 views

basic, innocent question: In bash scripting, why ever using a function, if one can set a variable containing command substitution with the essence of the function - a certain command or set of ...
futurewave's user avatar
-1 votes
1 answer
162 views

I am preparing a script that will try to detect two texts on the same line.  This pattern is present in my application log files, which then further used to identify which file contains the pattern. ...
Piyush Nikhade's user avatar
1 vote
2 answers
331 views

Command substitution, or Inline Execution as I call it, $() in Bash allows for text returns; before the execution of a main command. How do I abort the main command, if a $() returns an error code ...
user5211's user avatar
4 votes
2 answers
485 views

I have several servers which have several files with deploy date info I need to parse, and get a local copy of the files which are 2 months old or older. #!/bin/bash # split on new line not space # ...
Nickotine's user avatar
  • 554
0 votes
1 answer
611 views

The below code is working: [ec2-user@ip restore]$ echo $snap_name manual-test-2024-01-11-11-26-19 [ec2-user@ip restore]$ aws rds describe-db-cluster-snapshots --db-cluster-identifier creditpoc3 --...
jayvardhan's user avatar
0 votes
0 answers
89 views

I have a command stored in a text file command which looks like this: command_name par1 par2 path/with/backslashes -option_1 3 -option_2 0.05 --option_3=* -p 'P001=A' -p 'P002=B' ... The three dots ...
Michele Ancis's user avatar
0 votes
4 answers
295 views

I want to create 12 directories named after the months. So I tried using locale to get the month names, piping to tr to separate them with commas, then put braces around and passed to mkdir. But ...
teraspora's user avatar
  • 111
-1 votes
1 answer
168 views

user@debian:~/test/B$ find .. .. ../A ../A/x ../A/y ../A/z ../B user@debian:~/test/B$ find ../A -type f -print0 |xargs -0 -i% realpath --relative-to=../A % x y z user@debian:~/test/B$ # But user@...
FriendFX's user avatar
  • 367
0 votes
1 answer
330 views

Here's the working diff command: $ diff -u <(echo 'foo:bar:baz' | tr : "\n") <(echo 'foo:baz' | tr : "\n") --- /dev/fd/11 2023-08-30 13:11:50 +++ /dev/fd/13 2023-08-30 13:...
Scoobie's user avatar
  • 101
2 votes
2 answers
255 views

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not. Essentially I need to parse a string to ipa-getcert's post-save argument which should ...
dmgeurts's user avatar
3 votes
2 answers
13k views

Given a YAML file, example.yaml: node: sub_node: get_this: I'd like to get a variable containing get_this using Mike Farah's yq and the string sub_node yaml="$(cat example.yaml)" ...
Lee's user avatar
  • 549
0 votes
2 answers
1k views

I have this command which I want to variabilize. Particularly I want the latest argument presence to depend on an environment variable. ansible-playbook --inventory inventories/ssg-dev deploy.yml --...
Guerric P's user avatar
  • 103
0 votes
0 answers
43 views

Does anyone know what the command !^ does in the bash shell? I know ! relates to history expansion and ^ relates to command substitution (when it's not being used in a regular expression when it ...
geckels1's user avatar
  • 173
0 votes
1 answer
261 views

I've written a short bash script to monitor the line count growth (wc -l) in a file which is receiving results from a loop. Thus: printf "Name of file to monitor\n" read file printf "...
Leighton 's user avatar
0 votes
1 answer
128 views

What I want Simplified command: echo "helloworld" | echo $1 I know, this would be possible with cat, but what if a command like echo does not take a file as input? My actual command: ls -...
Bog's user avatar
  • 1,154
1 vote
0 answers
115 views

I tested a few scripts with different shells, and the results differ. # test 1 foo(){ echo $(al);} alias al='echo 123' foo # test 2 alias al='echo 123' foo(){ echo $(al);} alias al='echo abc' foo # ...
anonymous's user avatar
0 votes
2 answers
76 views

Consider the following shell script function: #!/bin/bash declare -a dir function() { local -a directories=( "A/B/C D" "E/F G H" ) #Initialize local array. printf "%q " ...
Eduardo's user avatar
0 votes
0 answers
56 views

I would like to try to write this command: while read -r repo; do gh repo delete $repo; done <<< $(gh repo list --no-archived) which basically cleans up my GitHub and deletes everything that ...
Julius Hamilton's user avatar
0 votes
0 answers
429 views

In bash shell, i generally use CTRL+R to fuzzy search a command that i executed recently. However the same doesn't seem to work for tcsh or csh shells. I want to understand if/how to do the same ...
Anuraag Tummanapally's user avatar
0 votes
1 answer
12k views

I am trying to replace a string within a couple of similar sql scripts. in my toolbox I have a for loop as well as grep and sed inside a bash script. #!/usr/bin/env bash for efa_instance in ...
vrms's user avatar
  • 287
1 vote
3 answers
104 views

The variable I wish to extract will look something like this ttyACM0 ttyACM1 I would like to iterate over this variable and issue the command: echo disconnect > /dev/ttyACM0 and then echo ...
Nir's user avatar
  • 11
0 votes
1 answer
153 views

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://...
Joe Burden's user avatar
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? For example, this command chia wallet show -w standard_wallet gives this result Wallet height: xxxxxx ...
God of Money's user avatar
4 votes
2 answers
1k views

I want to achieve the parameter substitution inside indirect expansion, but I cannot achieve it with a single command. I get a "bad substitution" error. Let me know if there's a clever way ...
Alapati Srikanth Chowdary's user avatar
1 vote
1 answer
36 views

Is there a way for bash or other shells' history to save the output of evaluated commands when it's a parameter? $ echo $(pwd) && history /root 0 I want something like: 1 echo $(pwd) &...
Jesse Taube's user avatar
-1 votes
1 answer
218 views

How do I call a command with on argument being the result of cat'ing a file? npx aws-api-gateway-cli-test \ --username $username \ --password $password \ --method $method \ --body cat user....
Sebastian Nielsen's user avatar
-1 votes
2 answers
133 views

My use case: I need to remove all dev packages listed in composer.json file. Suppose I have two packages: projectx/package-nice and projecty/package-good. To remove them I need to run: $ composer ...
Lawrence's user avatar
  • 329
2 votes
2 answers
2k views

I have the following example: $ a="$(ls)" $ echo $a backups cache crash lib local lock log mail opt run snap spool tmp $ $ echo "$a" backups cache crash lib local lock log mail ...
t7e's user avatar
  • 323
1 vote
2 answers
2k views

Before switching to fish shell, I frequently used various commands in zsh with which some_command. An example might be: $ file `which zsh` /opt/local/bin/zsh: Mach-O 64-bit executable arm64 /bin/zsh: ...
ylluminate's user avatar
0 votes
2 answers
228 views

There are many commands that accept multiple parameters, like touch, ls and rm. So that I can use the construct {1..3} to generate multiple parameters for the command. For example: [root@192 ~]# touch ...
Fajela Tajkiya's user avatar
1 vote
2 answers
1k views

Suppose I have a bash variable like this: tmp1='$(echo foo)' or tmp2='`echo foo`' How to achieve foo as result? I know that removing the command substitution from the string should work, but is ...
simonmysun's user avatar
0 votes
1 answer
85 views

for command substitution in bash, we do this hello=$(ls -la) echo "$hello" but when i do the same for below command,it fails,it says RANDOM not found hell=$(RANDOM) echo "$hell"...
TheGameiswar's user avatar
3 votes
1 answer
139 views

I have the following code to run pylint on all files in a Git repository with file extension .py, fed by command substitution. pylint $(git ls-files '*.py') The script runs just fine except when ...
JohnnieL's user avatar
  • 133
0 votes
0 answers
22 views

I have troubles with whitespaces and command substitution. I made a tiny script to show the problem: #! /bin/bash a="toilet -t --font='Dot Matrix' --filter metal --filter border ABC" #a=&...
tres.14159's user avatar
0 votes
1 answer
656 views

I'm trying to write a simple command that will create symlinks for all files in a specific directory (Yes, exactly like lndir but I cannot use it so I try to mimic it). I tried the following using ...
Avi Shukron's user avatar
2 votes
1 answer
228 views

printf "%s" `echo ../.. | sed 's/[.]/\\&/g'` printf "%s" $(echo ../.. | sed 's/[.]/\\&/g') printf "%s" "$(echo ../.. | sed 's/[.]/\\&/g')"
Nor Vegia's user avatar
1 vote
2 answers
292 views

I am asking why these three commands give three different answers: $ printf "%s\n" `echo ../.. | sed 's/[.]/\\&/g'` &&/&& $ printf "%s\n" $(echo ../.. | sed '...
eracesa's user avatar
  • 13
9 votes
3 answers
7k views

I want to check if a user is able to use sudo - but without the need to write the password - for bash shell scripts purposes. I did some research and I found: Sudo - is there a command to check if I ...
Manuel Jordan's user avatar

1
2 3 4 5
9