Location: In Aachen, a little town in germany with about 500.000 citiziens, near to belgium and the netherlands
Posts: 2
Thanks Given: 0
Thanked 0 Times in 0 Posts
$OPTARG changes commandline input
Hi there,
I hope, that I do not open an thread, that is already existing, but I didn't found something matching with my problem while searching for problems with "getopts"
My problem ist, that I'm taking arguments from commandline into my script with getopts, I've an flag -s, after that there comes an path to an *.sql File.
e.g. script.sh -s /batch/alpha/database/create_db.sql
This is no problem, but I want to have it more save, want, that the custumer must exactly hit ONE file, even, if he/she is using joker like *.
Therefore I wanted to count the hits, and if there is more than 1 hit, the script should terminate.
But if I type for example: ./script.sh -s /test/test*.sql and in the directory are the files "test.sql" and "test1.sql" I will not find the term "/test/test*.sql" in $OPTARG but "/test/test1.sql" !!!
Is there any chance, perhaps some kind of quoting, that I can get what I typed in on the commandline?? Only then I could check, if the term produces more than one matchings.
Thank you for the help and excuse my worse English, as I'm coming from Germany.
Location: In Aachen, a little town in germany with about 500.000 citiziens, near to belgium and the netherlands
Posts: 2
Thanks Given: 0
Thanked 0 Times in 0 Posts
I'm afraid, that you don't understand my problem right now.
I'm reading many arguments with getopts from the commandline. Many of them are optional. My problem is, that I'm reading an argument, that includes an absolute path, as "/test/test*.sql". When I read the argument from $OPTARG, I found the joker "*" substituted with the first file, that matches, for example, "/test/test1.sql", but I need the non substituted argument, so that I can use the input.
So if I had a variable with "/test/test*.sql" I could do the following:
e.g.:
.
.
.
other programmcode
This is the part in my script, reading arguments from the shell:
Hi,
I want to capture space as well from the argument
eg:
script.ksh -m "Message from xyz" -e "email@xyz.com"
script.ksh -m 'Message from xyz' -e 'email@xyz.com'
I am parsing using getopts, but for option "m" OPTARG is returning only "Message".
Please use code tags next time for... (9 Replies)
EDIT: -- SOLVED --
Heyas,
Getting used to optargs, but by far not understanding it.
So i have that script that shall be 'changeable', trying to use the passed arguments to modify the script visuals.
Passing:
browser -t test -d sect $HOME
Where -t should change the title,
and -d... (0 Replies)
mymk target
How to check is on commandline or no?
Cannot to find out ;(
Know that I need to use if.....new in shell sorry
Please use code tags next time for your code and data. (2 Replies)
I have a script that has commandline switches that work no problem. But i don't know how to enable it to have multiple switches at one time. So I'd want
myscript -h -o or even myscript -ho but i'm having no luck incorporating this. I tried shifting but i'm not getting it. Thanks
----------... (0 Replies)
here is the code
echo begin
while getopts 1:2:3:4: mode
do
case $mode in
1)echo "You have chosen mode1"
case $OPTARG in
a) echo "User Specified Date Range"
rangelist.sh ;;
b) echo "user specified month and year";;
?) echo "Default, Current... (4 Replies)
Hi,
I am using curl to hit a url using http in solaris 10 using commandline, I want to transfer an attachment(using multipart curl -F) also as a part of the request. If anyone has used kindly help me with the syntax. I am using below command:
/usr/local/bin/curl -v... (1 Reply)
Hi I have below code in one of my shell script:
if ; then fail $USAGE; fi
while getopts hz:r:t:dz: o
do
case "$o" in
h) echo $USAGE ; exit 0;;
r) export REQ_ID="$OPTARG";;
t) TIMESPAN="$OPTARG";;
d) detail="true";;
) ... (0 Replies)
Hi
I'm learning how to add in programm another option by command line.
For example in the "my_prog" i want to add a " -k " option and then write a number.
I mean:
my_prog -k 50
and the i should use the number 50.
I'm reading about getopt_long and optarg, and what i have done in the code... (0 Replies)
Hello Friends,
I need to pass arguments to a shell scripts. but for this i need to take the arguments only if they are supplied to the script as arguments.
Like :
Prompt > scriptname -d device_cd -s message
so how do i capture these arguments ?> i think we have to use optarg.but i dont... (5 Replies)