Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 请教各位老师1个shell 脚本的问题

I have a question for the teachers about a shell problem.
I defined a function ab
, which is supposed to receive a parameter to execute the tiup cluster exec
command. However, the awk '{print $1}'
inside the command treats $1
as the function’s parameter, which is not the expected behavior. Is there any way to avoid this?
ab(){
name="$1"
echo $name
ck=`tiup cluster exec $name --command "hostname -I | awk '{print \$1}'"`
}
ab "test"