- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- what is command line arguments.. ??
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
тАО06-30-2004 04:12 PM
тАО06-30-2004 04:12 PM
Could you tell me about comman line arugments while creating script. Then how set variable name like $0,$1,..$9,${10}..etc.
Atfer how to call this in program..
Explain in details.
Thanks In advance
Shankar
Solved! Go to Solution.
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 04:16 PM
тАО06-30-2004 04:16 PM
Re: what is command line arguments.. ??
It is something like ..
useradd kapil
useradd command's $1 argument is "kapil" if u r to write a shell script for useradd i would write it as follows
=================
#!/usr/bin/sh
username=$1 # Storing the first command line argument on to another variable called username
/usr/bin/useradd $username
=================
Regds,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 04:21 PM
тАО06-30-2004 04:21 PM
Re: what is command line arguments.. ??
================
#!/usr/bin/sh
echo $0's first argument is $1
echo $0's second argument is $2
echo $0's third argument is $3
================
Save this script as script1.sh
chmod 755 script.sh
./script.sh kapil you yourgf
Now look at the output and you should be clear
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 05:27 PM
тАО06-30-2004 05:27 PM
Re: what is command line arguments.. ??
Have a look at the ksh manpage:
Positional parameters, parameters denoted by a number, can be assigned
values with the set special command. Parameter $0 is set from
argument zero when the shell is invoked.
as explained by Kapil you can run his script and see the output. This mechanism of parameter passing holds true even in case of functions called in the shell script.
manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 05:32 PM
тАО06-30-2004 05:32 PM
Re: what is command line arguments.. ??
tst:
#!/usr/bin/sh
# A=$1 will fail!!!
B="$1"
C="$2"
echo "First arg: $B"
echo "Second arg: $C"
Example: tst "1 2 3" two
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 06:59 PM
тАО06-30-2004 06:59 PM
Re: what is command line arguments.. ??
Simple way to analyse is create script as follows with name say "scr1" and let us assume you are passing 4 arguments to it:
# vi scr1
#!/usr/bin/sh
echo $0
echo $1
echo $2
echo $3
echo $4
:wq!
# chmod +x scr1
# ./scr1 one two three four
The output will be
scr1 one two three four
Now $0 is the command itself i.e. scr1 and $1 is the first argument, $2 second and so on.
Hope that helps.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 07:02 PM
тАО06-30-2004 07:02 PM
SolutionCommand line arguments as like $1... ${N} can be used in the shell scripts,
as it is. By default $0 indicates in the shell script to denote it's filename, If we use the path name in the file execution as like
ksh /home/test/user.ksh 1 2 "hai bye test" "hello"
$0 is the /home/test/user.ksh
If we use the shell funtions,then $0 denotes the function name except test. If we use the funtion with test,it won't print the funtion name.
$# is used to give the number of command line arguments in the shell script execution.
$* is used to give the command line arguments as "$1 $2" like a string of all arguments
$@ is used to give the command line arguments as "$1" $2" .. "$N" like a individual strings
$! is used to get the running script's process ID
$? is used to get the return value of last executed shell command
See ksh man page for more details for command line arguments
Regards,
Muthukumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-30-2004 07:36 PM
тАО06-30-2004 07:36 PM
Re: what is command line arguments.. ??
I suggest read page 50-52 of the follwing guide:
http://www.docs.hp.com/hpux/pdf/B2355-90046.pdf
sks