Get the name of the caller script in bash script

前端 未结 9 1873
长情又很酷
长情又很酷 2020-12-04 23:58

Let\'s assume I have 3 shell scripts:

script_1.sh

#!/bin/bash
./script_3.sh

script_2.sh



        
9条回答
  •  执念已碎
    2020-12-05 00:19

    You can simply use the command below to avoid calling cut/awk/sed:

    ps --no-headers -o command $PPID
    

    If you only want the parent and none of the subsequent processes, you can use:

    ps --no-headers -o command $PPID | cut -d' ' -f1
    

提交回复
热议问题