passing arguments to external script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing arguments to external script
# 8  
Old 04-04-2011
Quote:
Originally Posted by gigagigosu
echo $all_PDFs
"/my_files/1.pdf" "/my_files/2.pdf"

/Scripts/Combine_PDFs_python.py -o /TEST`date +%H-%M-%S`.pdf $all_PDFs
this command produces an empty PDF (incorrect)
There is no quote removal done on the results of parameter expansion. The file names seen by the python script in this case include those quotes.

Quote:
Originally Posted by gigagigosu
/Scripts/Combine_PDFs_python.py -o /TEST`date +%H-%M-%S`.pdf "/my_files/1.pdf" "/my_files/2.pdf"
this command produces a correct result, the only difference is replacement of $all_PDFs with content... what am i doing wrong?
In this example, the shell will remove those quotes after it's done processing the command, so the python script will not see those quotes as part of the filenames.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 9  
Old 04-04-2011
and how can i pass the correct paths if i have weird characters?
# 10  
Old 04-04-2011
Code:
all_PDFS="$(echo $all_PDFS | tr -d '"')"

Depending on your shell you may be able to accomplish this with less expensive string operations as well.

If your shell's extremely old you may have to use backticks instead of $( )
# 11  
Old 04-04-2011
Corona688,

thank you but that didn't solve the issue with weird names within paths. files with names containing spaces (as an example) will be omitted from being joined, all other ones will be joined properly.
# 12  
Old 04-04-2011
Quote:
Originally Posted by gigagigosu
my script is:

Code:
source_folder=/my_files
cd "$source_folder"
if [ "$(ls -A)" ]; then
for PDF_file in *
 do
  quoted_filename=\"$source_folder/$PDF_file\"
  all_PDFs="$all_PDFs $quoted_filename"
 done
fi

echo "$all_PDFs"
/Scripts/Combine_PDFs_python.py -o /TEST`date +%H-%M-%S`.pdf "$all_PDFs"

this will output:
Code:
 "/my_files/1.pdf" "/my_files/2.pdf"

my python script (part of the OS) is supposed to join these PDFs but it produces an empty PDF
Quote:
Originally Posted by gigagigosu
and how can i pass the correct paths if i have weird characters?
Why not simply do the following instead?
Code:
source_folder=/my_files
/Scripts/Combine_PDFs_python.py -o /TEST`date +%H-%M-%S`.pdf "$source_folder"/*

Pathname expansion, which expands the asterisk into the filenames, happens after field splitting and all other subsitutions. This is by design. It is immune to "weird characters".

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 13  
Old 04-04-2011
alister,

that's the difference between an amateur like me and a pro like you Smilie you need only 2 lines to complete a script
# 14  
Old 04-04-2011
Quote:
Originally Posted by gigagigosu
Corona688,

thank you but that didn't solve the issue with weird names within paths. files with names containing spaces (as an example) will be omitted from being joined, all other ones will be joined properly.
You can't help unwanted things splitting on spaces when your list is separated by spaces.

Most here could have suggested that if you'd posted your complete script, or at least what your actual intentions are("want to combine all PDF's in this folder", not "want to split this string so I can feed names into a thing"). Without that, we're stuck working with what you've given us.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing arguments to php script

i want to be able to pass arguments to a php script if it is being piped: cat myphpscript.php | php - $1 $2 $3 blah blah This usually works for other script languages...i.e. ruby: cat myrubyscript.rb | ruby - $1 $2 $3 blah blah so my question is, how can i pass arguments to my php... (1 Reply)
Discussion started by: SkySmart
1 Replies

2. Shell Programming and Scripting

Passing arguments while running the script

Hi, I have a requirement for creating a MQ (queue) where the inputs has to be passed as arguments. Running the script as below ./hi.sh "Servername" "QueueManagername" "QueuecreationCommand" cat hi.sh echo "Welcome to $1" runmqsc $2 < $3 But the queue creation command is... (9 Replies)
Discussion started by: Anusha M
9 Replies

3. Shell Programming and Scripting

Passing arguments to a bash script

Hi, I wanted to pass an argument to a bash script. So that the argument is used inside the awk command inside the bash script. I know the noraml way of passing argument to a bash script as below : sh myScript.sh abc Inside the bash script i can use like this myArg1=$1 wc $myArg But... (8 Replies)
Discussion started by: shree11
8 Replies

4. Shell Programming and Scripting

Passing arguments to a perl script

Hi I need to pass comma seperated arguments to a perl script? It is like: Exect.pl -d GUI1,GUI2,GUI3 and I need to store these argsGUI1,GUI2,GUI3 in an array. can anyone suggest how to do that: (1 Reply)
Discussion started by: rkrish
1 Replies

5. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

6. Shell Programming and Scripting

passing arguments to sql script

Hi Gurus, i have one requirement in unix script, i have a file called abc.txt in that few lines are there with the empid, i need to read each line and pass to .sql script. ex: abc.txt 2345 2346 1243 1234 i need to pass these arguments to .sql script rom unix ex: select * from... (1 Reply)
Discussion started by: Devendar
1 Replies

7. Shell Programming and Scripting

problem passing arguments to script

Hi, I am writing a script, which is invoked from other system using ssh. I have problems reading the arguments passing to the script. If the argument has a space in it (ex "rev 2.00"), the script considers "rev" as 1 argument and "2.00" as another. Instead i want "rev 2.00" to be considered... (5 Replies)
Discussion started by: cjjoy
5 Replies

8. UNIX for Advanced & Expert Users

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... (7 Replies)
Discussion started by: rm-r
7 Replies

9. Shell Programming and Scripting

Passing arguments to a Perl script

I am playing around with Perl and wrote the script below that is executed from the command line, it will split data up in a file based on a value supplied. When executed you provide two arguments - the file that contains the data to be split and the character you want to split by. It works as... (4 Replies)
Discussion started by: jyoung
4 Replies

10. Shell Programming and Scripting

Passing arguments to a script

I've written a script (bgrep) for a more advanced grep command (& attached a cut down version below). I'm trying allow all grep options to be used, or in any combination. The script works fine if I type say bgrep -i -files product it will return a non-case sensitive list of matches for... (3 Replies)
Discussion started by: Kevin Pryke
3 Replies
Login or Register to Ask a Question