Map PID to namespace#

this script doing map pid to namespace

example, I doing unshare -r --net bash, and get the pid via echo $$. now I want map this pid into namespace that be executed using ip link set <IFACE> netns <HERE_OUR_NS>

map2ns.sh#
 1jump_mk_netns() {
 2        mkdir -p /var/run/netns
 3}
 4
 5map_pid2ns() {
 6        pid=$1
 7        nsname=$2
 8
 9        ln -s /proc/$pid/ns/net /var/run/netns/$nsname
10}
11
12echo "mapping $1 into $2"
13
14if [[ -d "/var/run/netns" ]]; then
15        echo "netns detected"
16        map_pid2ns $1 $2
17else
18        jump_mk_netns
19        map_pid2ns $1 $2
20fi