0
votes

I have a network namespace and I want to run command with this netns bash pid, how can I do it in bash script? Code example:

sudo ip netns add ns1 #this is my network namespace

#In separate shell I have to run following commands
sudo ip netns exec ns1 bash
echo $BASHPID #I want to use this bash pid in the next command

sudo iw phy phy0 set netns xxxx # xxxx is the example of bash pid

Is it possible to run this in one bash script? When I try to do it by using command to open another shell and save bash pid as a variable it doesn't work.

I tried in my script to open another terminal and use sudo ip netns exec ns1 bash and save $BASHPID` to variable it wasn't work.