Get the name of the caller script in bash script

前端 未结 9 1870
长情又很酷
长情又很酷 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:01

    Couple of useful files things kept in /proc/$PPID here

    • /proc/*some_process_id*/exe A symlink to the last executed command under *some_process_id*
    • /proc/*some_process_id*/cmdline A file containing the last executed command under *some_process_id* and null-byte separated arguments

    So a slight simplification.

    sed 's/\x0/ /g' "/proc/$PPID/cmdline"
    

提交回复
热议问题