Passing arguments while running the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing arguments while running the script
# 1  
Old 11-14-2014
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"

Code:
cat hi.sh

echo "Welcome to $1"
runmqsc $2 < $3

But the queue creation command is throwing error as below.

Code:
$ ./hi.sh "xclx111" "QASSSSS" "DEFINE QL("HI")"
Welcome to xclx111
./hi.sh: line 2: $3: ambiguous redirect


$ ./hi.sh xclx111 QASSSSS DEFINE QL("test")
-ksh: syntax error: `(' unexpected

Can someone please help on fixing this issue.

Thanks,
Anusha M
# 2  
Old 11-14-2014
Input redirection needs to be from a file, a here document or -string, or a process substitution (latter in recent shells), which none of your positional parameters is. Try using either of above.
# 3  
Old 11-14-2014
Hi Rudic,

The purpose is to automate running this script using a tool. So the manual activity of changing the file which is passed as argument is impossible.

Every time the requirement changes for queue/channel/subscription creation, deletion, alteration, display. And the 3rd argument is a command of MQ

Code:
For example:
./hi.sh "Servername" "QueueManagername" "QueuecreationCommand"

Requirement 1:
./hi.sh "xclx111" "QASSSSS" "DEFINE QL("hi")"

Requirement 2:
./hi.sh "xclx111" "QASSSSS" "DISPLAY QS("hi")"


DEFINE QL("hi")
DISPLAY QS("hi")

These are MQ commands for queue creation and display respectively


Can you please suggest on this.

Thanks,
Anusha M
# 4  
Old 11-14-2014
can you try using single quotes around the queue creation command
# 5  
Old 11-14-2014
Unless you find a way to massage the function/effect/output of the MQ command into any of the above, you're doomed.
IF you want redirection, that is. From your wording I infer you might need sth else. Do you?
# 6  
Old 11-14-2014
Quote:
Originally Posted by Anusha M
Hi Rudic,

The purpose is to automate running this script using a tool. So the manual activity of changing the file which is passed as argument is impossible.
Do you mean those arguments are things you'd usually be typing into the script? < expects a filename, to feed text into it you'll want a pipe. Maybe something like:

Code:
echo "Welcome to $1"
# Put $2 and $3 inside double quotes to prevent them splitting upon spaces
echo "$3" | runmqsc "$2"

It's also important to note that your requirements are broken, these won't work:

Code:
Requirement 1:
./hi.sh "xclx111" "QASSSSS" "DEFINE QL("hi")"

Requirement 2:
./hi.sh "xclx111" "QASSSSS" "DISPLAY QS("hi")"

...because you cannot put quotes inside quotes like that. You could do this:

Code:
Requirement 1:
./hi.sh "xclx111" "QASSSSS" 'DEFINE QL("hi")
Code:
'
Requirement 2: ./hi.sh "xclx111" "QASSSSS" 'DISPLAY QS("hi")'

...as long as you're aware that variables don't expand inside single quotes. You couldn't do 'DISPLAY QS("$shellvariable")' and expect $shellvariable to be substituted.

If you can do "DEFINE QL('$shellvariable')" that's quite okay.

You can also escape things with \ inside double-quotes like "DEFINE QL(\"value\")"

Last edited by Corona688; 11-14-2014 at 11:36 AM..
# 7  
Old 11-14-2014
An expanded here string containing a command substitution might work.
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 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

3. 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

4. Shell Programming and Scripting

passing arguments to external script

Hi! I have a python script that requires arguments and these arguments are file paths. This script works fine when executed like this: /my_python_script "file_path1" "file_path2" (i added quotes as some file names may have weird characters) the issue happens when i launch my python script... (14 Replies)
Discussion started by: gigagigosu
14 Replies

5. 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

6. 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

7. Shell Programming and Scripting

passing runtime arguments to a shell script...

hi I am new to shell programming.....my question is while running one of my shell program it stops in between to accept input from the user and proceeds furthur after giving input....I want to know whether I can set this input through some files so that the shell acript reads the input from the... (10 Replies)
Discussion started by: santy
10 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