Results 1 to 2 of 2
I created a script to get an argument out of some string. This script will be used by other scripts to parse string.
Code:
#!/bin/bash
if [ $# -lt 2 ...
- 05-25-2008 #1Just Joined!
- Join Date
- May 2008
- Posts
- 1
Bash - getarg.sh <arg#> <argument>
I created a script to get an argument out of some string. This script will be used by other scripts to parse string.
Examples:Code:#!/bin/bash if [ $# -lt 2 ]; then echo "Usage: $0 <argnum> <arg>" exit 1 fi num=$1 shift echo `eval echo '$'$num`
$ ./getarg.sh 1 hi how are "you ?"
hi
$ ./getarg.sh 4 hi how are "you ?"
you ?
1) Is there away for me to do this without having to execute a script? i.e. using getopts or something similar?
2) If not is this the best way of doing it?
Thanks all
!
- 05-25-2008 #2
im not sure that i understood the question but if what you mean is
1) instead of calling this script in the final script can I parse the arguments directly in the final script?
then the answer is yes. you can use getopts to do this . but in that case you will need to introduce options like you see them in every Unix-like tool( for example "top -n 1").
getopts is explained here
getopts
sorry if i misunderstood your questionLinux and me it's a love story


Reply With Quote