Quantcast
Channel: User Dennis Williamson - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 61

Answer by Dennis Williamson for How to determine the path to a sourced tcsh or bash shell script from within the script

$
0
0

In tcsh, $_ at the beginning of the script will contain the location if the file was sourced and $0 contains it if it was run.

#!/bin/tcshset sourced=($_)if ("$sourced" != "") then    echo "sourced $sourced[2]"endifif ("$0" != "tcsh") then    echo "run $0"endif

In Bash:

#!/bin/bash[[ $0 != $BASH_SOURCE ]] && echo "Script is being sourced" || echo "Script is being run"

Viewing all articles
Browse latest Browse all 61

Trending Articles