Problem in argument passing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in argument passing
# 1  
Old 09-23-2008
Problem in argument passing

Hell all,

i have a problem in argument passing.

print()
{
a=$1
b=$2
c=$3

echo $a
echo $b
echo $c
}

x="1 2 3"
y="4 5 6"
z="7 8 9"

print $x $y $z.



i am passing x,y and z to the function print.

it has to take the x , y and z . and it has to print as bellow

1 2 3
4 5 6
7 8 9


but it is printing as bellow.
1
2
3.

Since the values are seperated by space. it is accepting the first variable x alone.

how to solve this?.
# 2  
Old 09-23-2008
Quote the arguments properly.
# 3  
Old 09-23-2008
use double quotes around variables and arguments.
# 4  
Old 09-23-2008
And don't use the name print as a function name, in ksh it's a built-in function!

Regards
# 5  
Old 09-23-2008
Change the function call to look like below :

print "${x}" "${y}" "${z}"

This should have worked , and yes as said by Franklin "print" is a buitin word in shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a second argument

I am trying to pass a second argument like so: if ] then export ARG2=$2 else message "Second argument not specified: USAGE - $PROGRAM_NAME ARG1 ARG2" checkerror -e 2 -m "Please specify if it is a history or weekly (H or W) extract in the 2nd argument" fi however, it always goes... (4 Replies)
Discussion started by: MIA651
4 Replies

2. Shell Programming and Scripting

Passing argument not retrieving.

Hi I have a script which am trying to pass an argument which am trying to call using $1 but its not taking the value inside the if loop as it showing the error as if: Empty if.. Any help on this will be helpful. #!/usr/bin/csh echo $1 if ('$1' == "pp") then echo "Printing $1" endif (4 Replies)
Discussion started by: rogerben
4 Replies

3. Shell Programming and Scripting

Argument passing

How to pass the alphabet character as a argument in case and in if block? ex: c=$1 if a-z ]] then echo "alphabet" case $1 in a-z) echo "the value is a alphabet" edit by bakunin: please use CODE-tags. We REALLY mean it. (9 Replies)
Discussion started by: Roozo
9 Replies

4. Shell Programming and Scripting

Help with passing argument

Hi, I have a script that is scheduled with cron and runs every night. The cron part looks like this: 00 20 * * 0,1,2,3,4,5,6 /usr/local/bin/BACKUP TBTARM HOT DELETE My issue is with the 3rd parameter. Somewhere in the script, i want to tell the script to delete some files if the 3rd... (7 Replies)
Discussion started by: dollypee
7 Replies

5. Shell Programming and Scripting

Passing user argument

Hi all: I'm trying to pass an argument to a command but it's being difficult. #!/bin/bash set -xv if ; then echo "More than 1 argument entered" echo "Please enter a month using 3 character names, ie, Jan, Mar, Apr, Dec" && exit 1 fi if ; then echo "Please enter a month using... (2 Replies)
Discussion started by: raggmopp
2 Replies

6. Shell Programming and Scripting

Problem passing directory as argument with awk

I'm trying to figure out what's getting passed as the argument when I try to pass a directory as an argument, and I'm getting incredibly strange behavior. For example, from the command line I'm typing: nawk -f ./test.awk ~ test.awk contains the following: { directory = $NF print... (13 Replies)
Discussion started by: mrplainswalker
13 Replies

7. Shell Programming and Scripting

passing Argument

Hi All, i have script like below.. echo "1) first option" echo "" echo "2) second option" echo "" echo "*) please enter the correct option" read select case $select in 1) echo "first option selected" ;; 2) echo "second option selected" ;; *) echo "please enter the correct... (4 Replies)
Discussion started by: Shahul
4 Replies

8. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies

9. Shell Programming and Scripting

Problem with Argument Passing

Greetings, I am wrapping the monitoring commands like vmstat, sar, iostat and call via arguments I want ./unix_stats.sh -v vmstat -p <SEC> -d <Duration> to give vmstat values, and similarly iostat etc.,. Also if I give ./unix_stats.sh -v vmstat -i iostat -p <SEC> -d <Duration> should give... (4 Replies)
Discussion started by: A_Rod
4 Replies

10. Shell Programming and Scripting

Passing argument from one script to other

Dear All, I have one script which accepts database name and user_id from the user, i have another script that will unload the data from all the tables based on the user_id accepted by the user. How can i pass the user_id from the 1st script to the other. My OS is sun solaris. Thanks in... (3 Replies)
Discussion started by: lloydnwo
3 Replies
Login or Register to Ask a Question