How to hold string array in shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to hold string array in shell scripts
# 1  
Old 03-27-2007
How to hold string array in shell scripts

Gents,

Below is the Shell script which I am trying to hold a string of array that is passed from a java file. But it is not working . Can any one please help me to by fixing it.

#!/bin/csh/
set copy = ($argv[*])
echo $copy[1] >> /home/users/bavananr/rrr.log
echo $copy[2] >> /home/users/bavananr/rrr.log
echo $copy[3] >> /home/users/bavananr/rrr.log
echo $copy[4] >> /home/users/bavananr/rrr.log

this should print - Raj Sok Rajesh brajesh
------------------------------------------------------
Below is the java program that i used to call above shell script.
It sucks Smilie

public class sample
{
public static void main(String args[]) {
String strCmd = "/home/users/bavananr/Raj.sh";
String str [] = {"Raj","Sok","Rajesh","brajesh"};
Process proc = null;
try{
proc = Runtime.getRuntime().exec(strCmd,str);
}catch (Exception e) {
System.out.println("Exception occurs "+e);
}
}
}
# 2  
Old 03-27-2007
try this
Code:
col_look="this is test"
set -A look $col_look
echo "${look[1]}"
echo "${look[2]}"
echo "${look[0]}"

# 3  
Old 03-27-2007
hi ,

My problem when string is "passed" as a parameter from java program and I would like to have a script how to hold the string array parameter and use it further

Thanks Smilie
# 4  
Old 03-27-2007
try this
Code:
x=$@
echo $x
set -A look $x
echo ${look[0]}

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies

2. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies

3. Shell Programming and Scripting

How to put the multiple job on-hold using shell script?

Hi.. I need to put multiple jobs on ON HOLD in Autosys.. please help me on this. For Example: 1)ABCD_EFGH_IJKL 2)abcd_efgh_ijkl (2 Replies)
Discussion started by: Maanjesh
2 Replies

4. Shell Programming and Scripting

Shell string array

Hi all, I want to create an array variable in shell, for example: #!/bin/sh name="foo" name="bar" name="baz" But above code didn't work, I also tried with: name=(foo bar baz) and set -A name foo bar baz but none of these worked. Another question is how to know the shell... (6 Replies)
Discussion started by: Roy987
6 Replies

5. Shell Programming and Scripting

split string into array in shell

Hi all, I want to split a string into array based on given delimiter, for example: String: "foo|bar|baz" with delimiter "|" into array: strArr to strArr with values foo, bar and baz. Thanks a lot. Roy987 (5 Replies)
Discussion started by: Roy987
5 Replies

6. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

7. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

8. Shell Programming and Scripting

Displaying Array Elements in Shell Scripts

Hi All, I am using the following piece of script to print all the array elements in a script by name compare.sh: 31 len=${#array }; 32 j=0; 33 #echo "The length of the array is : $len" 34 while ; do 35 temp=${array} 36 echo "$temp" 37 let $j++ 38 done But I am getting the... (2 Replies)
Discussion started by: ananddr
2 Replies

9. UNIX for Advanced & Expert Users

MAX SIZE ARRAY Can Hold it

Hi, Do anyone know what's the max size of array (in awk) can be store before hit any memory issue. Regards (3 Replies)
Discussion started by: epall
3 Replies
Login or Register to Ask a Question