HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Function call in script
Operating System - HP-UX
1833870
Members
1763
Online
110063
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
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
12-29-2001 07:17 AM
12-29-2001 07:17 AM
Hello all,
I am writing a script that requires the user to input 3 variables. To make the program more robust, I want to check each variable just to see if anything has been entered. If nothing has been entered the user is prompted to enter again.
Instead of writing the same script piece 3 times, my thinking was to write a function that would check to see if anything had been entered.
My problem is: How can I call the function 3 times with 3 different variables and have it return the correct variables? I have attached the program as it stands and so far I have it checking the 1st variable. I want to use the same function to check all 3 variables.
Thank you.
Sanjay
I am writing a script that requires the user to input 3 variables. To make the program more robust, I want to check each variable just to see if anything has been entered. If nothing has been entered the user is prompted to enter again.
Instead of writing the same script piece 3 times, my thinking was to write a function that would check to see if anything had been entered.
My problem is: How can I call the function 3 times with 3 different variables and have it return the correct variables? I have attached the program as it stands and so far I have it checking the 1st variable. I want to use the same function to check all 3 variables.
Thank you.
Sanjay
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2001 09:04 AM
12-29-2001 09:04 AM
Solution
Hi Sanjay,
I'm not a script guru but you could do something like this:
#!/bin/sh
#
function checknum
{
echo "Enter "$PROMPT": \c"
read VAR
while [ "$VAR" = "" ]
do
echo "You must enter "$PROMPT" (Ctrl-C to quit)\n"
echo "Enter "$PROMPT": \c"
read VAR
done
}
#
PROMPT="Input base"
checknum
ib=$VAR
#
PROMPT="Output base"
checknum
ob=$VAR
#
PROMPT="Number to convert"
checknum
newin=$VAR
#
echo Input base: $ib
echo Output base: $ob
echo Number to convert: $newin
Darrell
I'm not a script guru but you could do something like this:
#!/bin/sh
#
function checknum
{
echo "Enter "$PROMPT": \c"
read VAR
while [ "$VAR" = "" ]
do
echo "You must enter "$PROMPT" (Ctrl-C to quit)\n"
echo "Enter "$PROMPT": \c"
read VAR
done
}
#
PROMPT="Input base"
checknum
ib=$VAR
#
PROMPT="Output base"
checknum
ob=$VAR
#
PROMPT="Number to convert"
checknum
newin=$VAR
#
echo Input base: $ib
echo Output base: $ob
echo Number to convert: $newin
Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2001 09:38 AM
12-29-2001 09:38 AM
Re: Function call in script
Hello Darrell,
Thank you for that. Your suggestion worked just fine.
Thanks again,
Sanjay
Thank you for that. Your suggestion worked just fine.
Thanks again,
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2001 08:00 PM
12-29-2001 08:00 PM
Re: Function call in script
You can call a function with values. They work just like running a script:
#!/usr/bin/sh
function TestParams
{
echo "$# params, 1=$1, 2=$2, all=$@"
return
}
TestParams 1 2 3 4 5
TestParams 123 456
---
Now to pass a parameter and modify the value, the easiest is to export the parameter at the start of the script. Now, all functions will know about this parameter and it won't have to be passed to the function in the call.
Bill Hassell, sysadmin
#!/usr/bin/sh
function TestParams
{
echo "$# params, 1=$1, 2=$2, all=$@"
return
}
TestParams 1 2 3 4 5
TestParams 123 456
---
Now to pass a parameter and modify the value, the easiest is to export the parameter at the start of the script. Now, all functions will know about this parameter and it won't have to be passed to the function in the call.
Bill Hassell, sysadmin
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 2025 Hewlett Packard Enterprise Development LP