-exec cmd in ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting -exec cmd in ksh script
# 8  
Old 09-16-2010
I see - but is there no way to do this without requiring the double quotes around the parameter passed to the script?

I can see people often forgetting to double-quote their parameter, with possibly terrible results!
# 9  
Old 09-16-2010
File name expansion is a shell feature that can be disabled with "set -f" in the user's shell but that would probably lead to more confusion.
# 10  
Old 09-16-2010
Perhaps I should first verify that the parameters are each quoted before I execute the find cmd - if they are not, I could terminate the script with an error message.

So I'd need to look for matching pairs of double-quotes. I should be able to do that fairly easily, I think.
# 11  
Old 09-17-2010
Quote:
Originally Posted by Tanuka
Perhaps I should first verify that the parameters are each quoted before I execute the find cmd - if they are not, I could terminate the script with an error message.

So I'd need to look for matching pairs of double-quotes. I should be able to do that fairly easily, I think.
That won't work. The quotes are removed by the shell before passing the parameters to the called program.
However, checking the arguments count should work as a workaround. If larger than the one expected, that would mean expansion had happen.
# 12  
Old 09-17-2010
Quote:
Originally Posted by jlliagre
That should be:

Code:
./cpmany . "f*" /joe/stuff/

Just one more comment on that, it happens because the shell is expanding the wildcard: "*" before starting the script.

Check below:
Code:
####################################
# Example files
####################################
# ls -1 f*
file1
file2
file3
file4
file5
####################################

####################################
# Example script
####################################
# cat myScript.sh
#!/bin/bash

argCount=1

for scriptArg in "$@"
do
        echo "Arg#: [${argCount}] - Value: [${scriptArg}]"
        argCount=`expr ${argCount} + 1`
done
echo "Find Result"
find $1 -maxdepth 1 -type f -name "$2"
####################################

####################################
# Exemple execution - No double quotes
####################################
# ./myScript.sh . f*
Arg#: [1] - Value: [.]
Arg#: [2] - Value: [file1]
Arg#: [3] - Value: [file2]
Arg#: [4] - Value: [file3]
Arg#: [5] - Value: [file4]
Arg#: [6] - Value: [file5]
Find Result
./file1
####################################

####################################
# Exemple execution - Double quotes
####################################
# ./myScript.sh . "f*"
Arg#: [1] - Value: [.]
Arg#: [2] - Value: [f*]
Find Result
./file2
./file1
./file4
./file5
./file3
####################################

I hope it helps!

Regards.
# 13  
Old 09-17-2010
Quote:
Originally Posted by felipe.vinturin
Just one more comment on that, it happens because the shell is expanding the wildcard: "*" before starting the script.
Indeed. I wrote how this expansion can be disabled in post #9 https://www.unix.com/302453896-post9.html
# 14  
Old 09-17-2010
Quote:
Originally Posted by jlliagre
Indeed. I wrote how this expansion can be disabled in post #9 https://www.unix.com/302453896-post9.html
Sorry, I didn't see that!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

2. Shell Programming and Scripting

Run few perl script in CMD using script

Hi, I have few PERL script which I have to run in CMD. I want to create a new script which will take care of running all these scripts in CMD.:confused: can any one suggest which script will be appropriate to solve my problem. Thanks in advance. (1 Reply)
Discussion started by: arup1980
1 Replies

3. Shell Programming and Scripting

exit status from ksh script exec from java using runtime

how do i get the exit status from a ksh or perl script executed in a java program using Runtime? (1 Reply)
Discussion started by: twk
1 Replies

4. Red Hat

setup sudo for cmd exec w/o password

i need to set up a user to execute a restricted command as another user and to be able to do so without entering a password. I understand the security concerns but let's not go there, unless you are really compelled to do so... The directive to permit is that I believe should work and did add to... (2 Replies)
Discussion started by: twk
2 Replies

5. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

ksh: cmd output to input of another script

I want to write a script in KSH that takes the output of one command and redisplays it. Something like: while true do read inpt date +"%I:%M:%S %p <-> $inpt" done and then some how get the output of the ping command to redirect to the input of this script. does that make sense? (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

8. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

9. Shell Programming and Scripting

How can I execute own ksh function in find -exec

Hi, I wrote a smiple ksh function send_notification() { ... } and want to execute it on each file, matched by the find command. I tried: find / -name "*.err" -mtime -8 -exec send_notification {} \; but it doesn't work. What should I do? I work in ksh on Hp-Ux. Regards, Pit (11 Replies)
Discussion started by: piooooter
11 Replies

10. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question