Answer the question
In order to leave comments, you need to log in
Bash script and return value
There is no experience in the tower.
I wrote this script.
#!/bin/bash
out=let ping -c 1 $1 | awk '/time=/{print $7}' | sed 's/time=//g'
out=let
Answer the question
In order to leave comments, you need to log in
According to this manual , let
calculates the value.
I have a question for the author of the question: why does it start at all out
? It's possible to do it like this:
#!/bin/bash
ping -c 1 $1 | awk '/time=/{print $7}' | sed 's/time=//g'
If you just drive the value into the variable:
out=$(something there)
Bashism, but it will be more reliable.
In your script, the construct out=let
sets the ping command to an environment variable out
with the value let
. Because ping does not use such a variable, out=let
you can just remove it and nothing will change. And the let command has nothing to do with it at all.
You can read about this way of setting environment variables in linux.die.net/man/1/bash in the Environment section :
The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above inPARAMETERS
. These assignment statements affect only the environment seen by that command.
out=blabla bash -c 'echo "$out"'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question