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 throwing error as below.

$ ./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

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.

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

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

can you try using single quotes around the queue creation command

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?

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:

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:

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:

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

Requirement 2:
./hi.sh "xclx111" "QASSSSS" 'DISPLAY QS("hi")'[/code] ...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\")"

An expanded here string containing a command substitution might work.

Thanks a lot!! It's working fine as below.

./queue_creation.sh QASSSSS 'DIS QL(TEST)'

What code did you end up using in the script?

Hi,
I had another requirement to ssh to a server and then execute the command. Hence used as below

cat queue_creation.sh 
ssh $1 "echo \"$3\" | runmqsc $2" 
./queue_creation.sh xccl1111 QASSSSS 'DIS QL(TEST)'

Thanks,
Anusha M