- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Pass local variable to global variable
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
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
- 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
- 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
- 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
- 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
- Report Inappropriate Content
03-09-2005 01:00 AM
03-09-2005 01:00 AM