วันอังคารที่ 15 พฤษภาคม พ.ศ. 2555

Bash source Command: $0 Can Not Determine It’s Own Location

The source command read and execute commands from a file. My parent.sh script source a script called child.sh. But, child.sh script can not determine It's own location developing use of $0. By default, $0 gives parent script location. How do I discover a script that is sourced at the command line can determine It's own location? My sample script:#!/bin/bash
# /var/www/html/java/tasks/child.sh
_me="$0"
# I want /var/www/html/java/tasks in _currentdir
_currentdir="$_me%/*"
echo "$_currentdir"
When I run from parent.sh:source child.shORsource /var/www/html/java/tasks/child.shThe $_currentdir is set to be the directory where parent.sh lives which is in /root/scripts/java/helper or . (current) directory. How do I fix this problem?  See More..

บทความที่ได้รับความนิยม