- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Few Questions
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
06-06-2007 02:46 AM
06-06-2007 02:46 AM
2. whats a $* in shell script
3. If $1 is the first parameter, whats $0
I tried echoing $# and it gave me 0 , i tried $? and I got 0 , I tried $* and it gave me nothing ... what does it mean.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 02:55 AM
06-06-2007 02:55 AM
Solution2. $* is set to the actual arguments passed to the script through the command line.
3. $0 is set to the name of the script you executed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:02 AM
06-06-2007 03:02 AM
Re: Few Questions
These variables, and other POSIX shell concepts, are described in sh-posix(1):
+ The following parameters are set automatically by the shell:
0 The string used to call the command or script, set from
invocation argument zero.
1, 2, ... The positional parameters.
*, @ All the set positional parameters, separated by a field
separator character. See the "Quoting" subsection.
# The number of set positional parameters in decimal.
- Flags supplied to the shell on invocation or by the set
command.
? The decimal exit status returned by the last executed
command.
$ The process number of this shell.
_ Initially, the absolute path name of the shell or
script being executed, as passed in the environment.
Subsequently, it is assigned the last argument of the
previous command. This parameter is not set for
commands which are asynchronous. This parameter is
also used to hold the name of the matching MAIL file
when checking for mail.
! The process number of the last background command
invoked.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:06 AM
06-06-2007 03:06 AM
Re: Few Questions
The sh-posix man page starts on page 340 in this document:
http://docs.hp.com/en/B2355-90903/B2355-90903.pdf
The "Parameter Substition" section is on page 351.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:10 AM
06-06-2007 03:10 AM
Re: Few Questions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:24 AM
06-06-2007 03:24 AM
Re: Few Questions
$? = result code of the previous command. The specific meaning of each command's result codes can be found from the command's man page, but the general definition is that 0 means "OK" and anything else "some error occurred".
$* = all parameters given to the script, in a single string.
Usually, "$@" (with the quotes) is more useful than this.
$0 = the command used to start the script.
This might be useful if the script needs to re-start itself, for example.
Example "test1.sh":
#!/bin/sh
echo "$0: $# args"
echo "\"$*\""
for i in "$@"
do
echo -n "\"$i\" "
done
echo
Try all these ways to start it:
sh test1.sh
sh test1.sh A
sh test1.sh A B
sh test1.sh A B C
sh test1.sh "arg with spaces" "another arg"
sh $PWD/test1.sh A B C
Read "man sh-posix" to find more information. It's a *long* man page.
MK