Questions tagged [command-substitution]

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

234 questions
-1
votes
2 answers

Bash function with parameters

I am trying to understand how to work with functions (that receive a argument) in bash. I did not get my code to work, the following code exemplifies my difficulties: #!/bin/bash fruit_code () { if [[ "$1" == "apple" ]]; then …
Miguel Garcia
  • 97
  • 1
  • 8
-1
votes
1 answer

bash command substitution executed as a single command not parsed as shell statement

It seems command subsitution take the first token as the command, remainings as the arguments of command, not parsed as shell statement. but the bash manual says that : Bash performs the expansion by executing command in a…
yuanjianpeng
  • 335
  • 1
  • 9
-1
votes
1 answer

Issue in executing docker command in bash script

I have following bash script code try to run a docker container through bash script but I am retreiving error. #!/bin/bash name=sudo docker ps | grep 'test' | awk '{print $1}' sudo docker exec -it $name bash error: docker exec requires at least…
ash luck
  • 17
  • 5
-1
votes
1 answer

Is there a way to display function output in bash command

Have a simple bash script I am working on with Mac, but I am having one issue. #!/bin/bash # Pull users IP from getifaddr on specfic port myip ( ) { #ipconfig getifaddr ppp0 local _ip _myip _line _nl=$'\n' while IFS=$': \t' read -a…
-1
votes
2 answers

awk command fails with command substitution

Running this command fails: $(printf "awk '{%sprint}'" $(tail -n +2 file.txt | cut -f2 | sort | uniq | awk 'BEGIN{a=1}{printf "gsub(\"%s\",%i);", $1,a++}')) file.txt It gives the following error: awk: ' awk: ^ invalid char ''' in…
BFH
  • 99
  • 7
-1
votes
1 answer

Bash assignment value to variable as command substitution and print value output

I would like to achieve this in Bash: echo $(a=1)and print the value of variable a I test eval, $$a,{}, $() but none of them work as most of the times either I got literally a=1 or in one case (I don't remember which) it tried to execute the…
Alex
  • 39
  • 1
  • 1
  • 5
-1
votes
1 answer

How can I call a Bash function without invoking command substitution?

I have a Bash function that has a Perl-style "or die". For example, #!/bin/bash func1 () { local val val=`cat foobar` || exit 7 echo "func1: cat returns $?" } myval=`func1` echo "Line X should not be reached (retn = $? val =…
KlaxSmashing
  • 335
  • 3
  • 12
-2
votes
1 answer

seq command unkown service or name

#!/bin/bash for ip in 'seq 1 254'; do ping -c 1 $0.$ip | grep "64 bytes" | cut -d " " -f 4 | tr -d ":" & done the file is ipsweep.sh when i run it show me this root@kali:ping: ./ipsweep.sh.seq: Name or service unkown
R3d_F1lc0n
  • 21
  • 4
-3
votes
2 answers

Passing multi-line command output to echo outputs only a single line

I have 2 files in my folder as shown below $ ls -l total 1 -rw-r--r-- 1 user user-group 0 May 10 14:49 test -rw-r--r-- 1 user user-group 0 May 10 14:49 test1 Listing the files is showing normal. But why does below command shows both the lines…
1 2 3
15
16