The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing runtime arguments to a shell script... santy Shell Programming and Scripting 10 01-09-2009 10:47 PM
Passing arguments to a shell script from file while scheduling in cron weblogicsupport SUN Solaris 4 01-27-2008 11:16 PM
Passing arguments to a Perl script jyoung Shell Programming and Scripting 4 12-29-2004 05:57 PM
Passing arguments to a script Kevin Pryke Shell Programming and Scripting 3 06-14-2002 09:06 AM
passing arguments jpprial UNIX for Dummies Questions & Answers 4 04-03-2001 11:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2008
rm-r rm-r is offline
Registered User
  
 

Join Date: May 2005
Location: Montreal
Posts: 17
Passing blank arguments to a script

All,
I have a cron job script that receives several command line arguments. At some point if there are validation problems and the job cannot be run, it duplicates the entire command line into a temporary text file which is later executed as a script. Unfortunately when I pass the list of received arguments (ie: $*) to this new file, the quoted blank arguments are dismissed.

For example, my script "runbatch.sh" looks like this:
#!/bin/ksh
#runbatch.sh
if [ some validation fails ]
then
echo "$0 $*" >> retryjobs.sh
exit 1
fi

If runbatch.sh was run as:
runbatch.sh one two '' four five

It will convert the 2 single quotes to a blank when exporting the line to retryjobs.sh, thus removing the blank argument.

Here's what retryjobs.sh looks like:
runbatch.sh one two four five

I need those single quotes to be passed. Any ideas anyone??

Thanks
  #2 (permalink)  
Old 01-08-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
There is actually an entry in the man page to explain exactly this situation; use "$@"
  #3 (permalink)  
Old 01-08-2008
rm-r rm-r is offline
Registered User
  
 

Join Date: May 2005
Location: Montreal
Posts: 17
How do you man "$@" ? It gives me errors:

->man "$@"
sh: @: Parameter not set.

Thanks,

Réal
  #4 (permalink)  
Old 01-08-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
no, I mean man ksh.

"$@" is what you should use in your script instean of $*
  #5 (permalink)  
Old 01-08-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Oh sorry, I forgot the other bit, and use printf, not echo.

Code:
printf "'%s' " "$@" >> file
printf "\n" >> file
  #6 (permalink)  
Old 01-08-2008
rm-r rm-r is offline
Registered User
  
 

Join Date: May 2005
Location: Montreal
Posts: 17
Thanks for the tip - I never tried man on ksh - kool

Unfortunately either "$@" or "$*" produce an unquoted double space

How about trying to replace this double space with [space] [quote] [quote] [space]. The 'tr' command doesn't seem quite fit to handle this. Remains 'sed' but I am not very familliar with it. Please help with the correct syntax:

echo "$@"|sed ??? >> retryjobs.sh

Thanks.

Réal
  #7 (permalink)  
Old 01-08-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
See my previous. I probably posted it while you were typing.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0