Store all the passed arguments in an array and display the array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store all the passed arguments in an array and display the array
# 1  
Old 05-17-2011
Store all the passed arguments in an array and display the array

Hi
I want to write a script which store all the parameters passed to the script into an array.
Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD.

I want to know how can I store the paramteres to array. It is a pretty simple but I don't know how to do it.
Can some one please help me.

Thanks and Advance
dgmm
# 2  
Old 05-17-2011
The arguments are already available in $@:

Code:
% cat s
#!/bin/ash

for arg; do
  printf '%s\n' "$arg"
done

% ./s a 'b c' d
a
b c
d

# 3  
Old 05-18-2011
Code:
# bash
declare -a arr=("$@")
#ksh
set -A arr "$@"

# 4  
Old 05-18-2011
Thank you.
This worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

Store args passed in array but not the first 2 args

Store args passed in array but not the first 2 args. # bash declare -a arr=("$@") s=$(IFS=, eval 'echo "${arr}"') echo "$s" output: sh array.sh 1 2 3 4 5 6 1,2,3,4,5,6 Desired output: sh array.sh 1 2 3 4 5 6 3,4,5,6 (2 Replies)
Discussion started by: iaav
2 Replies

4. Shell Programming and Scripting

Store value in array with awk

Hi everybody I wanna store some values that r in a .txt file in some arrays for example I have: 32782 28 32783 02 32784 01 32785 29 32786 25 32787 25 32788 00 32789 25 32790 02 32791 29 32792 23 32793 01 32794 28 and I need to save the first... (4 Replies)
Discussion started by: Behrouzx77
4 Replies

5. Shell Programming and Scripting

How to read values and store in array?

I am reading a value from a file and want to store the value in a dynamic array as i don't know the number of occurrences of the value in that file. How can i do that and then later fetch that value from array (25 Replies)
Discussion started by: Prachi Gupta
25 Replies

6. Shell Programming and Scripting

Match Pattern and store next value into array

Hi, I am trying to write a script which parses a log file and will eventually put the values in an array so that I can perform some math on it. In this file I am only interested in the last 200 lines so here is the command I use to display the contents in a manageable manner. tail -200... (3 Replies)
Discussion started by: Filter500
3 Replies

7. Shell Programming and Scripting

How to store output of command to an array

Hello Guys, I am trying to store output of command to an array and then want to print, but it showing an error that "bad substitution". I am not getting why it's happening. Can anyone help me? #!/usr/bin/sh hr=0 min=0 i=1 last $1 | grep -w `date "+%b"` | grep -v '\(0:.*\)' | grep -vw sshd... (8 Replies)
Discussion started by: kasparov
8 Replies

8. UNIX for Dummies Questions & Answers

trying to store variables in an array

im looping through an array setting three variables each time (one of the variables gives me the position in the array and is incremented each loop) im trying to then set the variables to that position in the array without much luck. any ideas? anArray=`$VAR1+$VAR2+"("$pos")"` (1 Reply)
Discussion started by: magnia
1 Replies

9. Shell Programming and Scripting

Store values in an Array

Hi all. Well, I have the next code: I need to make an array with the values I have in the bucle, but just don't get it... Question is, how can I store in an array that values, and how can I display them with echo? (8 Replies)
Discussion started by: crcbad
8 Replies

10. Shell Programming and Scripting

bash array passed to oracle

Hi all.. Does anyone know have an example of passing the contents of a bash array to oracle? basically I am looking to loop through the contents of a file(not csv!) and store each line into a bash array. Once i have this I can then pass the array into an oracle procedure that accepts an array... (1 Reply)
Discussion started by: satnamx
1 Replies
Login or Register to Ask a Question