- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh scripting concepts
Operating System - HP-UX
1755095
Members
1368
Online
108829
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
Discussions
Discussions
Forums
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
тАО03-13-2011 04:54 PM
тАО03-13-2011 04:54 PM
ksh scripting concepts
Hi,
i'm not sure if i'm in the right forum.. i'm on my 6th day in studying Unix Shell (specifically ksh scripting) and i need help about some concept that i cannot specifically find over the net (maybe i should say this - my background is Visual Basic scripting):
- what's the concept of variable settings for:
1. main script '(do variables here become "global" and can be used within called functions?)
2. functions '(do variables created here retain its values once script has exited from the function?)
3. (any sub procedures in ksh?)
4. can we create "Environment" variables in ksh? (i mean variables that are created anywhere but can be used throughout the whole script)
please itemize your replies.. it means a lot.. thanks!
~michael
i'm not sure if i'm in the right forum.. i'm on my 6th day in studying Unix Shell (specifically ksh scripting) and i need help about some concept that i cannot specifically find over the net (maybe i should say this - my background is Visual Basic scripting):
- what's the concept of variable settings for:
1. main script '(do variables here become "global" and can be used within called functions?)
2. functions '(do variables created here retain its values once script has exited from the function?)
3. (any sub procedures in ksh?)
4. can we create "Environment" variables in ksh? (i mean variables that are created anywhere but can be used throughout the whole script)
please itemize your replies.. it means a lot.. thanks!
~michael
- Tags:
- ksh
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2011 05:25 PM
тАО03-13-2011 05:25 PM
Re: ksh scripting concepts
Hi Michael:
1. Variables are global in scope and can be used (updated and/or referenced in all functions (subroutines).
2. Variables declared in the scope of a subroutine are actually added to the global namespace unless they are declared with 'typeset' in which case they are local to the subroutine and "disappear" (or are restored to their global state) once the subroutine is exited.
For example, consider:
#!/bin/ksh
X=michael
function who
{
echo "my last 'Y' was '${Y}'"
typeset Y=somebody
Z=whoever #...no typeset...
echo "my global value is '${X}'"
typeset X=someone_else
echo "my local value is '${X}'"
echo "I am '${Y}'"
}
who
echo "'${X}' and '${Y}' and '${Z}'"
exit 0
3. I'm not sure what you mean by "sub procedures".
4. Environmental variables are variables that are inherited from a process's parent. A child process can use and modify an environmental variable but any modification is not propagated back to its parent. See #1, above.
Regards!
...JRF...
1. Variables are global in scope and can be used (updated and/or referenced in all functions (subroutines).
2. Variables declared in the scope of a subroutine are actually added to the global namespace unless they are declared with 'typeset' in which case they are local to the subroutine and "disappear" (or are restored to their global state) once the subroutine is exited.
For example, consider:
#!/bin/ksh
X=michael
function who
{
echo "my last 'Y' was '${Y}'"
typeset Y=somebody
Z=whoever #...no typeset...
echo "my global value is '${X}'"
typeset X=someone_else
echo "my local value is '${X}'"
echo "I am '${Y}'"
}
who
echo "'${X}' and '${Y}' and '${Z}'"
exit 0
3. I'm not sure what you mean by "sub procedures".
4. Environmental variables are variables that are inherited from a process's parent. A child process can use and modify an environmental variable but any modification is not propagated back to its parent. See #1, above.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2011 06:56 PM
тАО03-13-2011 06:56 PM
Re: ksh scripting concepts
>3. any sub procedures in ksh?
You can have aliases. And functions in other files through FPATH.
You can have aliases. And functions in other files through FPATH.
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP