To read and execute commands from given FILENAME in the current shell use the following syntax:
OR
. /path/to/file
The . (dot) is one of the KSH built-in commands. You can also use an alias called source as follows:
. /path/to/lib.ksh
source /path/to/lib.ksh
Example
Create a script called /tmp/lib.ksh as follows:Create a script called test.ksh:
#!/bin/ksh
# defaul values ##
vech="Bus"
rent=14
type="A/C"
# Display info
function showvech {
printf "Vehicle: %s\n" $vech
printf "Type (ac or non-ac): %s\n" $type
printf "Rent (per/km): Rs.%d km\n" $rent
}
# Set info
function setvech {
vech="$1"
rent=$2
type="$3"
}
Sample outputs:
#!/bin/ksh
# source our /tmp/lib.ksh
. /tmp/lib.ksh
# show defaults
showvech
# set new values and display it back
setvech "Jeep" 9 "Non-A/C"
showvech
Vehicle: Bus
Type (ac or non-ac): A/C
Rent (per/km): Rs.14 km
Vehicle: Jeep
Type (ac or non-ac): Non-A/C
Rent (per/km): Rs.9 km
No comments:
Post a Comment