![]() |
|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
![]() |
|
Thread Tools | Display Modes |
|
|||
![]()
Ok, so you have a script called /bin/script.sh - when you follow that with arguments like First and Last there are already variables built in to allow you to use them.
/bin/script.sh First Last is going to store the value of First in $1 and Last in $2 - so if you script contained something like: #!/bin/sh echo "Your name is: $1 and your surname is: $2" you'd be closer to solving this problem. EDIT: Actually, this is pretty ugly - there's a fairly good introductory tutorial over here. Last edited by dk_netsvil; 9th July 2008 at 05:21 PM. |
|
||||
![]()
Also see getopt(1), although I'm not sure how portable this is.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
||||
![]()
/bin/sh provides a builtin getopts command as a replacement for the getopt program. In FreeBSDs manual page for sh(1) the following information is provided on getopts:
Code:
getopts optstring var The POSIX getopts command. The getopts command deprecates the older getopt(1) command. The first argument should be a series of letters, each possibly followed by a colon which indicates that the option takes an argument. The specified variable is set to the parsed option. The index of the next argument is placed into the shell variable OPTIND. If an option takes an argument, it is placed into the shell variable OPTARG. If an invalid option is encountered, var is set to `?'. It returns a false value (1) when it encounters the end of the options. OpenBSDs version of the public domain Korn Shell also implements it, the GNU Bourne Again (bash) shell should too. ---- getopts is only useful in your shell scripts if you want to make a script behave like normal unix programs. For example, wc -l file prints only the number of lines in 'file', where the wc program usually prints lines, words, and bytes. The getopt manual page that Carpetsmoker posted explains how to do things like that in a script. the difference in using the external getopt and the internal getopts command is basically an 's', technical advantages aside.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
shell script with zenity | bsdnewbie999 | OpenBSD General | 5 | 24th April 2009 02:37 AM |
shell script-start another process | bsdnewbie999 | Programming | 2 | 23rd April 2009 07:48 PM |
shell script compare md5 sum | bsdnewbie999 | Programming | 1 | 11th April 2009 02:20 PM |
incrementing within a shell script? | spiderpig | Programming | 5 | 29th September 2008 08:12 PM |
Shell Script. | bsdnewbie999 | Programming | 21 | 15th July 2008 07:54 AM |