GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting problem with functions
Operating System - HP-UX
1846743
Members
5904
Online
110256
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2004 03:20 AM
01-30-2004 03:20 AM
I have a script that I have cleaned up by incorporating functions, instead of one big ugly mess.
I am alittle unclear with the use of functions.
This is what I want to do...
I need to keep track on how long it takes to run a specific function, (with in this function it reads another script, and so on)
So I though I would set it up this way...
backup () {
STARTOFFLINEBU=$SECONDS
script stuff...
ENDOFFLINEBU=$SECONDS
((OFFLINEBU_TIME=($ENDOFFLINEBU - $STARTOFFLINEBU) /60))
# export $OFFLINEBU_TIME
echo;echo;echo "Time to complete Offline Backup: $OFFLINEBU_TIME minutes."
}
This script runs alright, until I get...
87: This is not an identifier.
I am assuming that the export is the problem?
Do I need to export the variable in the function if I want to use it else where? Like later on in the script?
# Time it took to complete backup
#ENDENTIREBU=$SECONDS
# ((OFFLINEBU_TIME=($ENDENTIREBU - $STARTENTIREBU) /60))
#echo;echo;echo
#echo " TIME "
#echo "Offline Backup Tar & Bzip2 Backup Complete Time"
#echo "==============================="
#echo $OFFLINEBACKUP_TIME%$TARBZIP2_TIME%$OFFLINEBU_TIME |
#awk -F% '{printf "%-10s %-15s %-15s" $1, $2, $3}'
I am alittle unclear with the use of functions.
This is what I want to do...
I need to keep track on how long it takes to run a specific function, (with in this function it reads another script, and so on)
So I though I would set it up this way...
backup () {
STARTOFFLINEBU=$SECONDS
script stuff...
ENDOFFLINEBU=$SECONDS
((OFFLINEBU_TIME=($ENDOFFLINEBU - $STARTOFFLINEBU) /60))
# export $OFFLINEBU_TIME
echo;echo;echo "Time to complete Offline Backup: $OFFLINEBU_TIME minutes."
}
This script runs alright, until I get...
87: This is not an identifier.
I am assuming that the export is the problem?
Do I need to export the variable in the function if I want to use it else where? Like later on in the script?
# Time it took to complete backup
#ENDENTIREBU=$SECONDS
# ((OFFLINEBU_TIME=($ENDENTIREBU - $STARTENTIREBU) /60))
#echo;echo;echo
#echo " TIME "
#echo "Offline Backup Tar & Bzip2 Backup Complete Time"
#echo "==============================="
#echo $OFFLINEBACKUP_TIME%$TARBZIP2_TIME%$OFFLINEBU_TIME |
#awk -F% '{printf "%-10s %-15s %-15s" $1, $2, $3}'
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2004 03:48 AM
01-30-2004 03:48 AM
Solution
Variables declared in functions have scope throughout the entire script unless specifically specified as "local". You don't have to export them.
I would like to know what line number 87 is in your script. Annoying problems like this are often the result of a test ("[[") where the variables tested are not what you were expecting them to be.
I would like to know what line number 87 is in your script. Annoying problems like this are often the result of a test ("[[") where the variables tested are not what you were expecting them to be.
Never preceed any demonstration with anything more predictive than "watch this"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2004 05:24 AM
01-30-2004 05:24 AM
Re: scripting problem with functions
Hi,
I think it is this line:
# export $OFFLINEBU_TIME
that produces the error, assumed it is not uncommented. Try changing it to:
# export OFFLINEBU_TIME
although - as Mark has pointed out - the line may not be necessary at all.
regards,
John K.
I think it is this line:
# export $OFFLINEBU_TIME
that produces the error, assumed it is not uncommented. Try changing it to:
# export OFFLINEBU_TIME
although - as Mark has pointed out - the line may not be necessary at all.
regards,
John K.
it would be nice if you always got a second chance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2004 05:38 AM
01-30-2004 05:38 AM
Re: scripting problem with functions
Hi,
What is your line 87?.
Below is a small example that the value of the variable will be saved through rest of the script.
$cat scr
func()
{
START=$SECONDS
sleep 10
END=$SECONDS
(( DIFF = ($END - $START) ))
echo "DIFF is $DIFF inside the function"
}
func
echo diff is $DIFF outside the function
$./func
DIFF is 10 inside the function
diff is 10 outside the function
-Sri
What is your line 87?.
Below is a small example that the value of the variable will be saved through rest of the script.
$cat scr
func()
{
START=$SECONDS
sleep 10
END=$SECONDS
(( DIFF = ($END - $START) ))
echo "DIFF is $DIFF inside the function"
}
func
echo diff is $DIFF outside the function
$./func
DIFF is 10 inside the function
diff is 10 outside the function
-Sri
You may be disappointed if you fail, but you are doomed if you don't try
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP