- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Question about variables in script
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
Discussions
Discussions
Forums
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
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
тАО04-04-2003 12:26 AM
тАО04-04-2003 12:26 AM
1. How can i check if variable exist or not in sh ? (I know how to do it in csh) E.G.
if [ $VAR not exist ]; then
VAR=$(expr $VAR + 1)
export VAR
else
VAR=0
export VAR
fi
2. What is the best syntax for arithmetic operations like VAR=$(expr $VAR + 1) in sh? I don't want to use expr command, i'd like something like VAR++ in C language.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 12:42 AM
тАО04-04-2003 12:42 AM
Re: Question about variables in script
your logic is rather strange. If *not* defined increment, else set to 0
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 12:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 12:49 AM
тАО04-04-2003 12:49 AM
Re: Question about variables in script
if [ $VAR not exist ]; then
VAR=0
export VAR
else
VAR=$(expr $VAR + 1)
export VAR
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 12:49 AM
тАО04-04-2003 12:49 AM
Re: Question about variables in script
Use the -z option as shown in man test
for an existing variable.
if [ -z "$var" ]
then
echo not set
fi
See typeset -i in sh man
typeset -i x=1
x=$x+1
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 12:51 AM
тАО04-04-2003 12:51 AM
Re: Question about variables in script
if [[ -n ${VAR:-} ]]; then
((VAR+=1))
else
VAR=0
fi
export VAR
2)
((VAR+=1)) -or-
((VAR=VAR+1)) -or-
VAR=$((VAR+1))
...
Best regards...
Dietmar.