S
S
SKYnv2013-02-08 10:34:24
bash
SKYnv, 2013-02-08 10:34:24

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'

The script fulfills correctly and returns value.
Actually the question is, why does the construction
out=let
return a value? And does it carry any hidden problems in itself.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
silvansky, 2013-02-08
@SKYnv

According to this manual , letcalculates 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'

And the script will display the result.

V
Vlad Zhivotnev, 2013-02-08
@inkvizitor68sl

If you just drive the value into the variable:
out=$(something there)
Bashism, but it will be more reliable.

P
Power, 2013-02-10
@Power

In your script, the construct out=letsets the ping command to an environment variable outwith the value let. Because ping does not use such a variable, out=letyou 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 in PARAMETERS. These assignment statements affect only the environment seen by that command.

Well, to fix it, you can run the command
out=blabla bash -c 'echo "$out"'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question