- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Pass local variable to global variable
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- Report Inappropriate Content
03-08-2005 04:23 AM
03-08-2005 04:23 AM
Pass local variable to global variable
Please throw some lights to the new guy. I have a shell script as following: The idea of the program is to get the value of $cur_uid from the IF loop, assign it to uidcurrent. In my WRK_FILE, I only have one line. It either equal to UID1 or UID2. As you may see in my program, I couldn't get the ideal results. I have tried diffent shells. It just won't work. Your help will be highly appreciated.
WRK_FILE=$newdbs_home/bin/.configdlyidcheck
TMP_FILE=/var/tmp/tmp.txt
uidcurrent=""
flag=""
cur_uid=""
if [[ -s $WRK_FILE ]]; then
cat $WRK_FILE | while read line
do
flag=$line
echo flag: $flag
if [ $flag = $UID1 ]; then
cur_uid=$flag #### this variable is used for echo/testing only
nxt_uid=$UID2
echo current uid in $WRK_FILE is: $cur_uid, and the next uid is: $nxt_uid > $TMP_FILE
echo $nxt_uid > $WRK_FILE
pg $WRK_FILE
elif [ $flag = $UID2 ]; then
cur_uid=$flag ##### this line is for testing only
nxt_uid=$UID1
echo current uid in $WRK_FILE is: $cur_uid, and the next uid is: $nxt_uid > $TMP_FILE
echo $nxt_uid > $WRK_FILE
pg $WRK_FILE ##### this line is for testing only
else
echo "The $WRK_FILE file is damaged and please check the load shell program" > $TMP_FILE
fi
echo "The Current User ID is: $cur_uid"
# uidcurrent=$cur_uid
# echo "The UIDCURRENT is: $uidcurrent"
done
uidcurrent=$cur_uid
echo "The UIDCURRENT is: $uidcurrent"
else
echo "The $WRK_FILE file does not exist" ###> $TMP_FILE
/bin/mail -s "The $WRK_FILE is damaged and can not load the data" ${mlist} < $TMP_FILE
fi
echo "the cur_uid is: $cur_uid" > /var/tmp/test2.txt
echo "The UIDCURRENT is: $uidcurrent" >> /var/tmp/test2.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-08-2005 05:07 AM
03-08-2005 05:07 AM
Re: Pass local variable to global variable
Here is the solution:
http://www.faqs.org/faqs/unix-faq/shell/bash/
Refer to question *E4*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-08-2005 09:52 AM
03-08-2005 09:52 AM
Re: Pass local variable to global variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-08-2005 10:04 AM
03-08-2005 10:04 AM
Re: Pass local variable to global variable
global foo = bar
www.python.org
--Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-08-2005 04:07 PM
03-08-2005 04:07 PM
Re: Pass local variable to global variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-09-2005 01:00 AM
03-09-2005 01:00 AM
Re: Pass local variable to global variable
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP