Sponsored Content
Top Forums Shell Programming and Scripting Passing space separated value to a function - error Post 302357616 by balamv on Wednesday 30th of September 2009 09:00:03 AM
Old 09-30-2009
Question Passing space separated value to a function - error

Taking inputs in the script which is space separated and passing this to a function and i have assigned like below
And then when I use for loop for the inputs i got from the user, it is taking only the first argument.
Code:
Enter Names : Bala Sundar Sridhar
read names
namesCheck $names

function namesCheck() {
myname=$1

for i in myname
do
printf "\n$i"
done
}

this is printing always the first name .. here as Bala

Pl help me how to get all values in the function.

Last edited by vgersh99; 09-30-2009 at 10:14 AM.. Reason: code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Parameter passing in a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (2 Replies)
Discussion started by: fastgoon
2 Replies

2. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

3. Shell Programming and Scripting

Problem while using grep (multi-level) with the space-separated filepath.

Hi, I've been trying to use grep to find out all the files which have two particular patterns in it (both pattern1 AND pattern2). I have a script to do the same, in which I'm getting the output of the first grep (with -l option) which contains the list of file paths and I'm trying to search for... (3 Replies)
Discussion started by: NanJ
3 Replies

4. Shell Programming and Scripting

How to loop through space separated values?

How do I loop thru space separated values in a variable? I hate to use very complicated counter increment logic for this kind of simple problem. Expected result(using ksh) $>echo "aaa bbbb cccc" | <looping code here> var=aaa var=bbbb var=cccc $>echo "aaa bbbb cccc" | while IFS=" "... (12 Replies)
Discussion started by: kchinnam
12 Replies

5. Shell Programming and Scripting

Passing arguments that contain space

hi All, i am trying to pass arguments that contain space , value will be stored in variables to be used further in script , i went thru previous posting , still its not clear to how to implement for my case. passing 3 args test.sh it is 'fun to work in unix' inside shell ... (3 Replies)
Discussion started by: gvkk
3 Replies

6. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

7. UNIX for Dummies Questions & Answers

How convert space separated list to matched columns?

Hi I have been racking my (limited) brains to get this to work without success I have a file output which is a list of lists - ie a single column of data that is separated by space into sub lists below - I need to both split this so that each list is in a separate column (eg tab or semicolon... (8 Replies)
Discussion started by: Manchesterpaul
8 Replies

8. Homework & Coursework Questions

C++ Attempting to modify this function to read from a (;) semi-colon-separated file

After some thought. I am uncomfortable issuing my professors name where, there may be unintended side effects from any negative responses/feedback. Willing to re post if I can omit school / professor publicly, but can message moderator for validation? I am here for knowledge and understanding,... (1 Reply)
Discussion started by: briandanielz
1 Replies

9. Shell Programming and Scripting

Need Help on For Loop to pass space separated value as one value

Hi, I am having a file say list1 with a output like below jun 12 18:23 may 20 18:23 Now i want to pass the above two values into for loop,I have written a script like this. #!/bin/bash a=`cat list1` for i in $a do echo "HI $i" done expected output: HI jun 12 18:23 (3 Replies)
Discussion started by: sumanthupar
3 Replies

10. Shell Programming and Scripting

Passing variable value in a function to be used by another function

Hello All, I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and put the variables in " ". Is there another way I can do this? Thank you in advance. readtasklist() { while read -r mod ver... (1 Reply)
Discussion started by: aderamos12
1 Replies
MAIN.C(1)						      Debian GNU/Linux manual							 MAIN.C(1)

NAME
pbc_merge - Merge multiple Parrot bytecode (PBC) files into a single PBC file. SYNOPSIS
pbc_merge -o out.pbc input1.pbc input2.pbc ... DESCRIPTION
This program takes two or more PBC files and produces a single merged output PBC file with a single fix-up table and constants table. Command-Line Options "-o out.pbc" The name of the PBC file to produce, containing the merged segments from the input PBC files. Functions "static void help(void)" Print out the user help info. "static PackFile_ByteCode* pbc_merge_bytecode(PARROT_INTERP, pbc_merge_input **inputs, int num_inputs, PackFile *pf)" This function merges the bytecode from the input packfiles, storing the offsets that each bit of bytecode now exists at. "static PackFile_ConstTable* pbc_merge_constants(PARROT_INTERP, pbc_merge_input **inputs, int num_inputs, PackFile *pf)" This function merges the constants tables from the input PBC files. "static void pbc_merge_debugs(PARROT_INTERP, pbc_merge_input **inputs, int num_inputs, PackFile_ByteCode *bc)" This function merges the debug segments from the input PBC files. "static void pbc_fixup_bytecode(PARROT_INTERP, pbc_merge_input **inputs, int num_inputs, PackFile_ByteCode *bc)" Fixup bytecode. This includes correcting pointers into the constant table and updating the ops mapping. "static void pbc_fixup_constants(PARROT_INTERP, pbc_merge_input **inputs, int num_inputs)" Fixup constants. This includes correcting pointers into bytecode. "static PackFile* pbc_merge_begin(PARROT_INTERP, pbc_merge_input **inputs, int num_inputs)" This is the function that drives PBC merging process. "static void pbc_merge_write(PARROT_INTERP, PackFile *pf, const char *filename)" This functions writes out the merged packfile. "int main(int argc, const char **argv)" The main function that grabs console input, reads in the packfiles provided they exist, hands them to another function that runs the merge process and finally writes out the produced packfile. Debian Project 2012-01-08 MAIN.C(1)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy