S
S
SurelL2018-08-31 18:23:01
linux
SurelL, 2018-08-31 18:23:01

Why doesn't the function read the parameter?

Good everyone!
With the terminal is still on you, so I can not figure it out.
There is a function that should take the server number from the loop:

function func() {
      ssh [email protected]$1.ru ....
}

for server in {01..03}
do 
     func $server
done

Stubbornly not reading $server

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2018-09-01
@saboteur_kiev

Everything should work.
Maybe you are not working in bash, but in some other shell?

$ cat a.sh
#!/bin/bash
function func() {
     echo ssh [email protected]$1.ru ....
}

for server in {01..03}
do
     func $server
done

$ ./a.sh
ssh [email protected] ....
ssh [email protected] ....
ssh [email protected] ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question