≡ Menu

bash version

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 using $0. By default, $0 gives parent script location. How do I find out a script that is sourced at the command line can determine it's own location? My sample script:

# /var/www/html/java/tasks/child.sh 
# I want /var/www/html/java/tasks in _currentdir 
echo "${_currentdir}"

When I run from parent.sh:

source child.sh


source /var/www/html/java/tasks/child.sh

The $_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?
[click to continue…]

Linux: Set Environment Variable

Bash shell is used for various purposes under Linux. How do I customize the shell environment variable under Linux operating systems?
[click to continue…]

HowTo: Unix For Loop 1 to 100 Numbers

I want to run a Unix command 100 times using a for loop from 1 to 100. Can you tell me how to take a block of numbers in a loop under KSH or BASH shell?
[click to continue…]